Пример #1
0
        private static void PrintAllRootLeafpaths(Node node,List<int> elements)
        {
            
            if (node == null)
            {
                return;
            }
            elements.Add(node.data);
            if (node.left == null && node.right == null)
            {
                Console.WriteLine(elements);
                elements.ForEach(item => Console.Write(item + " "));
                Console.WriteLine();
            }
            PrintAllRootLeafpaths(node.left, elements);
            PrintAllRootLeafpaths(node.right, elements);
            
            elements.RemoveAt(elements.Count - 1);

        }
Пример #2
0
        public static Node ConstructTree()
        {

            Node n1 = new Node(1);
            Node n2 = new Node(2);
            Node n3 = new Node(3);
            Node n4 = new Node(4);
            Node n5 = new Node(5);
            Node n6 = new Node(6);
            Node n7 = new Node(7);

            n1.left = n2;
            n1.right = n3;
            n2.left = n4;
            n2.right = n5;
            n3.left = n6;
            n3.right = n7;

            return n1;
        }
Пример #3
0
 public Node(int data)
 {
     this.data = data;
     left = null;
     right = null;
 }