Pergunta

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.

Foi útil?

Solução

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?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top