# Implementation with BFS and TreeMap

• ``````public class Solution {
// BST and PowerNode which wraps up TreeNode and index of column.
// the idea similar to finding top view of a binary tree
// http://algorithms.tutorialhorizon.com/print-the-top-view-of-a-binary-tree/
public List<List<Integer>> verticalOrder(TreeNode root) {
List<List<Integer>> listSet = new ArrayList<List<Integer>>();
if (root == null) {
return listSet;
}

Map<Integer, List<Integer>> map = new TreeMap<Integer, List<Integer>>();

while (!queue.isEmpty()) {
PowerNode pnode = queue.poll();
if (!map.containsKey(pnode.col)) {
List<Integer> list = new ArrayList<Integer>();
map.put(pnode.col, list);
} else {
List<Integer> list = map.get(pnode.col);
}

if (pnode.node.left != null) {
}
if (pnode.node.right != null) {
}
}

// the reason to use treemap is we can output it here in order.
for (List<Integer> list : map.values()) {
}

return listSet;
}

public class PowerNode {
int col;
TreeNode node;
public PowerNode(int col, TreeNode node) {
this.col = col;
this.node = node;
}
}
}``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.