문제

I have to write a routine that prints the root of a binary search tree in a recursive way. The function has the form

printTheRoot() {

    printTheRoot(someNode)

}

printTheRoot(Node node) {

     ....

}

I am not looking for specific code, just for an idea or pseudo-code on how this could be done. Personally, I do not think recursion is necessary but it is a requirement for this assignment.

도움이 되었습니까?

해결책

Does node have a property parent? And if it does, is that property of type Node? If so, the answer should be obvious to you (if you're comfortable with recursion).

Remember that all recursive functions must have an exit condition. What do you think the exit condition for this function should be?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top