Friday, September 13, 2013

find min and max node of a BST

public int findMin(Node node) {
        if (node == null) {
            return 100;
        }
        while (node.leftChild != null) {
            node = node.leftChild;
        }
        return node.data;
    }

    public int findMax(Node node) {
        if (node == null) {
            return -100;
        }
        while (node.rightChild != null) {
            node = node.rightChild;
        }
        return node.data;
    }

No comments:

Post a Comment