public BSTNode<T> convertToDLL(BSTNode<T> root) {
        if(root == null) {
            return root;
        }
        // this is to get hold of parent with not null left child ..
        if(root.left != null) {
            // recursively convert left subtree to DLL
            BSTNode<T> leftNode = convertToDLL(root.left);
            // assign head of doubly linked list ..
            if(head == null) {
                head = leftNode;
            }

            // find inorder predecessor
            for(;leftNode.right != null; leftNode = leftNode.right);

            // make root next of the predecessor
            leftNode.right  = root;
            // make predecessor prev of root
            root.left = leftNode;
        }
        // similarly for right subtree .. above condition gives you root which has notNull left child
        if(root.right != null) {
            // recursively convert right subtree to DLL
            BSTNode<T> rightNode = convertToDLL(root.right);
            // find inorder successor
            for(;rightNode.left != null; rightNode  = rightNode.left) ;
            // make root previous element of the successor
            rightNode.left = root;
            // make successot next node of the root
            root.right = rightNode;
        }

        return root;
    }