SHARE
TWEET

Untitled

SKREFI Oct 13th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Node
  5. {
  6. public:
  7.     int data;
  8.     struct Node *left, *right;
  9.     Node(int data)
  10.     {
  11.         this->data = data;
  12.         left = right = NULL;
  13.     }
  14. };
  15.  
  16. void printTree(struct Node *node) //in order print, gen ala de la stanga la dreapta
  17. {
  18.     if (node == NULL)
  19.         return;
  20.     printTree(node->left);
  21.     cout << node->data << " ";
  22.     printTree(node->right);
  23. }
  24.  
  25. vector<int> v;
  26. void treeToVector(struct Node *node) //in order print, gen ala de la stanga la dreapta
  27. {
  28.     if (node == NULL)
  29.         return;
  30.     treeToVector(node->left);
  31.     v.push_back(node->data);
  32.     treeToVector(node->right);
  33. }
  34.  
  35. int main()
  36. {
  37.     struct Node *root = new Node(1);
  38.     root->left = new Node(2);
  39.     root->right = new Node(3);
  40.     root->left->left = new Node(2);
  41.     root->left->right = new Node(4);
  42.     root->left->right->left = new Node(5);
  43.     root->left->right->right = new Node(2);
  44.  
  45.     treeToVector(root);
  46.     int counter = 0;
  47.     for (auto i : v)
  48.     {
  49.         cout << i << " ";
  50.     }
  51.  
  52.     //cout << counter;
  53.     cout << endl;
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top