Traversal Algorithm Using Stacks In Python