using System.Collections.Generic;
public static void Main()
Dictionary<int,int> dict=new Dictionary<int,int>();
foreach(var key in dict.Keys){
Dictionary<int,List<NodeLevel>> dictLevelLists=new Dictionary<int,List<NodeLevel>>();
LevelsListsStack(a,ref dictLevelLists,0);
foreach(var key in dictLevelLists.Keys){
Console.WriteLine("Level - "+key.ToString());
foreach(var node in dictLevelLists[key]){
Console.Write(node.node.data.ToString()+"->");
public static void DFT(Node root){
Stack<Node> s=new Stack<Node>();
if(x.right!=null) s.Push(x.right);
if(x.left!=null) s.Push(x.left);
Console.WriteLine(x.data.ToString());
public static void VerticalSum(Node root,ref Dictionary<int,int> dict,int level)
VerticalSum(root.left,ref dict,level-1);
if(!dict.ContainsKey(level))
dict.Add(level,root.data);
VerticalSum(root.right,ref dict,level+1);
public static void LevelLists(Node root,Dictionary<int,List<Node>> levels,int level){
if(levels.ContainsKey(level))
levels.Add(level,new List<Node>{root});
LevelLists(root.left,levels,level+1);
LevelLists(root.right,levels,level+1);
public static void LevelsListsStack(Node root, ref Dictionary<int,List<NodeLevel>> levels,int level){
Stack<NodeLevel> s=new Stack<NodeLevel>();
s.Push(new NodeLevel(root,0));
if(levels.ContainsKey(n.level))
levels.Add(n.level,new List<NodeLevel>{n});
s.Push(new NodeLevel(n.node.left,n.level+1));
s.Push(new NodeLevel(n.node.right,n.level+1));
public NodeLevel(Node n,int level){