psuedo code for how to process stacks