Ik heb BST van BTNode<E>'s elk is voorzien van dubbele nummer en ik heb de volgende gebieden:
BTNode <E> root: Een verwijzing naar de wortel van de boom
BTNode <E> current: Een pointer naar het huidige knooppunt
Ik wil een methode Next () dat de huidige punten leveren aan het knooppunt dat de volgende waarde van de huidige node waarde moet schrijven
Hier is wat ik tot dusver heb gedaan:
public boolean Next()
{
// List<E> tempList = new ArrayList<E>(); // Creating new list (I defined this at the begining of the class)
E tempValue = current.getElement(); // Gets the value of current element
makeSortedList(root); //
E[] tempArray = (E[]) tempList.toArray(); // Convert the list to an array
int index = Arrays.binarySearch(tempArray, tempValue); // Find the position of current node value in the array
if(index >= count) // count is no. of nodes in the tree
{
E targetValue = tempArray[index + 1]; // Store the target value in a temporary variable
search(targetValue); // This method searches for the node that has targetValue and make that node as the current node
return true;
}
else return false;
}
// This method takes the values of the tree and puts them in sorted list
private void makeSortedList(BTNode<E> myNode)
{
if(myNode != null)
{
makeSortedList(myNode.getLeft());
tempList.add(myNode.getElement());
makeSortedList(myNode.getRight());
}
}
Kunt u mij helpen deze methode te schrijven?













