I have this method and it should show on the screen the smallest n Elements in BST, Example n=3, the smallest 3 elements and so on..
Unfortunately at running, it shows that its reaching an Empty content and gets shut down. Further notes, the method should give and int back and its not void, but I couldn't find another way to show all the Elements, because return type int will give just one Element? right?
public int sorteduptp(int n) {
if (n > 0 && !isEmpty()) {
BinarySearchTree current = this;
while (!current.leftChild.isEmpty() && current.size() != n) {
current = current.leftChild;
}
if (n == 1) {
System.out.println(current.leftChild.getContent());
return 0;
} else {
sorteduptp(n - 1);
while (!current.isLeaf()) {
System.out.println(current.getContent());
System.out.println(current.rightChild);
}
System.out.println(current.getContent());
}
}
}