Definition at line 21 of file main.cpp.
◆ postorderTraversal()
| vector< int > Solution::postorderTraversal |
( |
TreeNode * |
root | ) |
|
|
inline |
Definition at line 24 of file main.cpp.
25 {
26 vector<int> answer = {};
27 if (root)
28 {
29 stack<TreeNode*> node_stack;
30 stack<TreeNode*> output_stack;
31 node_stack.push(root);
32 while (!node_stack.empty())
33 {
34 TreeNode* current = node_stack.top();
35 node_stack.pop();
36 output_stack.push(current);
38 node_stack.push(current->
left);
40 node_stack.push(current->
right);
41 }
42 while (!output_stack.empty())
43 {
44 answer.push_back(output_stack.top()->val);
45 output_stack.pop();
46 }
47 }
48 return answer;
49 }
Definition for a binary tree node.
References TreeNode::left, and TreeNode::right.
Referenced by main().
The documentation for this class was generated from the following file: