st0le
10/8/2013 - 9:05 PM

Binary Search Tree to Double Linked List.

Binary Search Tree to Double Linked List.

        private Node toDBList(Node node) {
            if (node.right == null && node.left == null)
                return node;
            if (node.left != null) {
                Node hold = toDBList(node.left);
                hold = hold.getRightMost();
                hold.right = node;
                node.left = hold;
            }
            if (node.right != null) {
                Node hold = toDBList(node.right);
                hold = hold.getLeftMost();
                hold.left = node;
                node.right = hold;
            }
            return node.getLeftMost();
        }