Pergunta de entrevista da empresa Palantir Technologies

Iterative in-order search?

Respostas da entrevista

Sigiloso

9 de dez. de 2010

Stack s = new Stack(); public void inOrderWithoutRecursion(node n) { while (!s.isEmpty() || n != null) { if (n != null) {// this is a normal call, recurse s.push(n); n = n.left; } else // we're returning: pop and print the current node { n = s.pop(); System.out.println(n.value); n = n.right; } } }

2

Sigiloso

1 de nov. de 2010

Use a stack.