Problem of the Day: 2 Stacks 1 Queue (update)

Sometimes the smallest thing messes up everything. I had a static marker on the head node so of course both stacks were the same! Oops. This caused the moving the items from one stack to the other problematic as they were the same stack. The other problem I ran into was I hadn’t considered the case of removing the last node from the head which caused some null pointer exceptions. All fixed now!

I re-used the head/node internal classes from POTD: Stacks & Queueus and remade the pop() and push() functions, then made the separate MyQueue class using two stacks as planned.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: