private void inOrder(BSTNode root) {
if (root.getElem().equals(null)) {
return;
}
inOrder(root.getLChild());
// print to array, increment 2
inOrder(root.getRChild());
}
So I believe printing to the array occurs at the comment line, since that is usually where the current node is outputted, but not sure how to send the in-ordered elements into an array? If it needs an extra parameter or different return type to make it work, that's ok, I can adjust it since it's a helper method.
Two things :
array
and index
to your method (signature change). There on you can simply add this line instead of the comment:
array[index++]= root.getData();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.