Beispiel #1
0
        //dpair	returnTreeAsList();						// return the tree as a list of dpairs
        public dpair returnTreeAsList()
        {
            dpair head = new dpair();
            dpair tail = new dpair();


            head.x = root.key;
            head.y = root.stored;
            tail   = head;

            if (root.left != leaf)
            {
                tail = returnSubtreeAsList(root.left, tail);
            }
            if (root.right != leaf)
            {
                tail = returnSubtreeAsList(root.right, tail);
            }

            if (head.x == 0)
            {
                return(null);         /* empty tree */
            }
            else
            {
                return(head);
            }
        }
Beispiel #2
0
        //dppair    consSubtree(element z);					// internal recursive cons'ing function
        public dpair returnSubtreeAsList(element z, dpair head)
        {
            dpair newnode, tail;

            newnode = new dpair();


            newnode.x = z.key;
            newnode.y = z.stored;
            head.next = newnode;
            tail      = newnode;

            if (z.left != leaf)
            {
                tail = returnSubtreeAsList(z.left, tail);
            }
            if (z.right != leaf)
            {
                tail = returnSubtreeAsList(z.right, tail);
            }

            return(tail);
        }
Beispiel #3
0
        //dpair	returnTreeAsList();						// return the tree as a list of dpairs
        public dpair returnTreeAsList()
        {
            dpair head = new dpair();
            dpair tail = new dpair();

            head.x = root.key;
            head.y = root.stored;
            tail = head;

            if (root.left  != leaf) { tail = returnSubtreeAsList(root.left,  tail); }
            if (root.right != leaf) { tail = returnSubtreeAsList(root.right, tail); }

            if (head.x==0) { return null; /* empty tree */} else { return head; }
        }
Beispiel #4
0
        //dppair    consSubtree(element z);					// internal recursive cons'ing function
        public dpair returnSubtreeAsList(element z, dpair head)
        {
            dpair newnode, tail;

            newnode = new dpair();

            newnode.x = z.key;
            newnode.y = z.stored;
            head.next = newnode;
            tail       = newnode;

            if (z.left  != leaf) { tail = returnSubtreeAsList(z.left,  tail); }
            if (z.right != leaf) { tail = returnSubtreeAsList(z.right, tail); }

            return tail;
        }