Karenai 0 Newbie Poster

Hi! For my assignment, I was required to implement an ordered dictionary using a binary search tree. I have most of it done, but I'm stuck on a this one problem.

My program needs to print the word from the dictionary that alphabetically follows the specified word (aka the successor). What throws me off is that the specified word doesn't actually have to be contained in the dictionary (it doesn't have to be stored in the binary search tree).

So, if I'm in interpreting the problem correctly, I would need to find the word in my BST that is the closest match to the specified word. And then finding the successor for that word. I'm just not too sure on how to go about doing that.

Here's my code for finding the successor, assuming the specified word is located in the binary search tree:

private BinaryTreeNode<DictEntry> successor(BinaryTreeNode<DictEntry> tempNode)
	{
		if (tempNode.getRightChild() != null)
			return findMin(tempNode.getRightChild());
		
		BinaryTreeNode<DictEntry> parent = tempNode.getParent();
			
		while (parent != null && tempNode == parent.getRightChild())
		{
			tempNode = parent;
			parent = parent.getParent();
		}
		
		return parent;
	}
	
	public String successor(String word)
	{
		current = find(root, word);
		
		BinaryTreeNode<DictEntry> successor = successor(current);
		
		if (successor == null)
			return "";
		else
			return successor.getNode().word();
	}

And here's my find method:

private BinaryTreeNode<DictEntry> find(BinaryTreeNode<DictEntry> tempNode, String word)
	{
		if(tempNode.getNode().word().compareTo(word) == 0)
			return tempNode;
		
		else if(word.compareTo(tempNode.getNode().word()) < 0 && tempNode.getLeftChild() != null)
				return find(tempNode.getLeftChild(), word);
		
		else if(word.compareTo(tempNode.getNode().word()) > 0 && tempNode.getRightChild() != null)
				return find(tempNode.getRightChild(), word);
		
		else
			return null;
	}

I hope this all makes sense.

If anyone can help point me in the right direction, I would really appreciate it.