The code works for me. What problem are you having?
If you're thinking "this is one backwards way to implement a queue and it seems horribly inefficient" then you're right :). It demonstrates that a queue can be created from a stack and that's great to show the theoretical versatility of a push-down automaton, but in practice, you'd never do it this way.