fork download
  1. // Following is the Binary Tree node structure
  2. /**************
  3. class BinaryTreeNode {
  4.   public :
  5.   T data;
  6.   BinaryTreeNode<T> *left;
  7.   BinaryTreeNode<T> *right;
  8.  
  9.   BinaryTreeNode(T data) {
  10.   this -> data = data;
  11.   left = NULL;
  12.   right = NULL;
  13.   }
  14. };
  15. ***************/
  16.  
  17. vector<int> sumTree(BinaryTreeNode<int>* root){
  18. /* Don't write main().
  19. * Don't read input from, it is passed as function argument.
  20. * Return output and don't print it.
  21. * Taking input and printing output is handled automatically.
  22. */
  23. int sum = 0;
  24. vector<int>v;
  25. if(root->left==NULL && root->right==NULL){
  26. sum = 0;
  27. v.push_back(sum);
  28.  
  29. }
  30. else{
  31. sum = root->left->data + root->right->data;
  32. v.push_back(sum);
  33. }
  34.  
  35. sumTree(root->left);
  36. sumTree(root->right);
  37. return v;
  38. }
  39.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:17:1: error: ‘vector’ does not name a type
 vector<int> sumTree(BinaryTreeNode<int>* root){
 ^~~~~~
stdout
Standard output is empty