SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
51
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- /*
- class Node
- int data;
- Node left;
- Node right;
- */
- void topView(Node root) {
- if (root == null) return;
- Stack<Node> stack = new Stack();
- while (root != null) {
- stack.push(root);
- root = root.left;
- }
- while (!stack.isEmpty()) {
- root = stack.pop();
- System.out.print(root.data + " ");
- }
- root = root.right;
- while (root != null) {
- System.out.print(root.data + " ");
- root = root.right;
- }
- }
RAW Paste Data

