print a multidimensional vector in c 2b 2b

Solutions on MaxInterview for print a multidimensional vector in c 2b 2b by the best coders in the world

showing results for - "print a multidimensional vector in c 2b 2b"
Rayan
21 Oct 2018
1// A recursive function able to print a vector
2// of an arbitrary amount of dimensions.
3template<typename T>
4static void show(T vec)
5{
6  std::cout << vec;
7}
8
9
10template<typename T>
11static void show(std::vector<T> vec)
12{
13  int size = vec.size();
14  if (size <= 0) {
15    std::cout << "invalid vector";
16    return;
17  }
18  std::cout << '{';
19  for (int l = 0; l < size - 1; l++) {
20    show(vec[l]);
21    std::cout << ',';
22  }
23  show(vec[size - 1]);
24  std::cout << '}';
25}