Exemplo n.º 1
0
 public static int SumTree(NodeTree tree)
 {
     if (tree == null)
     {
         return(0);
     }
     return(SumTree(tree.L) + SumTree(tree.R) + tree.value);
 }
Exemplo n.º 2
0
        public static void CheckTree(NodeTree tree)
        {
            Node2 list = new Node2();

            list.value = 0;
            Node2 head = list;

            Tree2List(tree, list);
            int s1 = SumList(head);
            int s2 = SumTree(tree);

            __VERIFIER_assert(s1 == s2);
        }
Exemplo n.º 3
0
        public static Node2 Tree2List(NodeTree tree, Node2 list)
        {
            if (tree == null)
            {
                return(list);
            }

            Node2 newNode = new Node2();

            newNode.value = tree.value;
            newNode.next  = null;
            list.next     = newNode;
            list          = newNode;
            list          = Tree2List(tree.L, list);
            list          = Tree2List(tree.R, list);

            return(list);
        }