Skip to content

Commit e2ee010

Browse files
authored
Merge pull request vJechsmayr#179 from pavan1645/feature/inorder_traversal
Inorder traversal
2 parents f04a397 + 01b8016 commit e2ee010

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var inorderTraversal = function(root) {
2+
let st = [];
3+
let visited = [];
4+
5+
while(root || st.length != 0) {
6+
while(root != null){
7+
st.push(root);
8+
root = root.left;
9+
}
10+
11+
root = st.pop();
12+
visited.push(root.val);
13+
14+
root = root.right;
15+
}
16+
17+
return visited;
18+
};

0 commit comments

Comments
 (0)