fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void printTree(string** tree, int height)
  6. {
  7. for(int i = 0; i < 3; i++)
  8. {
  9. cout << "tree[" << i << "] = { ";
  10. for(int j = 0; j < height; j++)
  11. {
  12. cout << tree[i][j] << " ";
  13. }
  14. cout << "}" << endl;
  15. }
  16. }
  17.  
  18. int main()
  19. {
  20. int maxNumberOfNodes = 5;
  21.  
  22. string* tree [3];
  23. for(int i = 0; i < 3; ++i)
  24. {
  25. tree[i] = new string[maxNumberOfNodes];
  26.  
  27. for(int j = 0; j < maxNumberOfNodes; ++j)
  28. tree[i][j] = to_string(j+1);
  29. }
  30.  
  31. printTree(tree, maxNumberOfNodes);
  32.  
  33. for(int i = 0; i < 3; ++i)
  34. delete[] tree[i];
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
tree[0] = { 1 2 3 4 5 }
tree[1] = { 1 2 3 4 5 }
tree[2] = { 1 2 3 4 5 }