Using a deque to manage the stack of nodes is faster here.