Hi
I am having a bit of trouble with a do while loop. I either can't get it to stop, or it doesn't do exactly as I need it to.
I am using a array called nums to insert random numbers into a binary search tree. Once the tree has been created I need to create a method to search the nums array looking for the node I have asked the user to find in the tree. Once it finds it I need it to output the nodes in that order into a vector.
Sometimes I ask for a node which is not in the tree - this is represented by the outCome. 0 if it is in the tree and 1 if it is not.
I'm attempting to do the first part, if the node is in the tree and have tried creating the following method. Currently it just loops. Can someone tell me how to tell it to stop?
Also, could you help me with telling it to only add nodes until it reaches the node they are searching for, represented by searchValue.
public void correctSearchPath(int searchValue){
if (outCome == 0) { // node is IN tree
System.out.println("correctSearchPath node is in tree");
for (i = 0; i < amount; i++){
do {
optimalSearch.add(new Integer(nums[i]));
System.out.println("searchValue is " + searchValue);
}
while (i != searchValue);
}
System.out.println("optimalsearchpath is: " + optimalSearch);
}
if (outCome == 1){ // node NOT in tree
for (i = 0; i < amount; i++){
System.out.println("correctSearchPath node is NOT in tree");
}
}
System.out.println("outcome of flipCoin is " + outCome);
} // method to drawWhole tree
hope someone can help me with this, its driving me and the program loopy :o