employer cover photo
employer logo
employer logo

Palantir Technologies

Is this your company?

Palantir Technologies interview question

Iterative in-order search?

Interview Answers

Anonymous

9 Dec 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

Anonymous

1 Nov 2010

Use a stack.