binary-tree-inorder-traversal 1.0.0
Binary Tree Inorder Traversal
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

vector< int > inorderTraversal (TreeNode *root)
 

Detailed Description

Definition at line 21 of file main.cpp.

Member Function Documentation

◆ inorderTraversal()

vector< int > Solution::inorderTraversal ( TreeNode root)
inline

Definition at line 24 of file main.cpp.

25 {
26 vector<int> answer = {};
27 stack<TreeNode*> node_stack;
28 TreeNode* current = root;
29
30 while (current != nullptr || !node_stack.empty())
31 {
32 while (current != nullptr)
33 {
34 node_stack.push(current);
35 current = current->left;
36 }
37 current = node_stack.top();
38 node_stack.pop();
39 answer.push_back(current->val);
40 current = current->right;
41 }
42
43 return answer;
44 }
Definition for a binary tree node.
Definition main.cpp:12
int val
Definition main.cpp:13
TreeNode * left
Definition main.cpp:14
TreeNode * right
Definition main.cpp:15

References TreeNode::left, TreeNode::right, and TreeNode::val.

Referenced by main().


The documentation for this class was generated from the following file: