We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticvoidinOrder(Noderoot){Stack<Node>stack=newStack<>();while(true){// Push all the nodes from the left.while(root!=null){stack.push(root);root=root.left;}// check if the stack is empty.if(stack.isEmpty()){return;}// pop them and print their data. Then go to the right.root=stack.pop();System.out.print(root.data+" ");root=root.right;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Inorder Traversal
You are viewing a single comment's thread. Return to all comments →
Using a Stack, withour recursion :)