First implementation, iterative, stack