Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement