SHARE
TWEET

Untitled

a guest Aug 20th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. queue<TreeNode*> q;         // To store the node addresses
  2. vector<int> result;         // To store the values in the node
  3. result.push_back(root->val);
  4. q.push(root);
  5. while (!q.empty()) {
  6.   node = q.front();
  7.   q.pop();  
  8.   if(node->left){
  9.     result.push_back(node->left->val);
  10.     q.push(node->left);
  11.   }else{
  12.       result.push_back(NULL);
  13.   }
  14.   if(node->right){
  15.     result.push_back(node->right->val);
  16.     q.push(node->right);
  17.   }else{
  18.       result.push_back(NULL);
  19.   }
  20. }
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