Implement Queue using Stacks

Posted on

Screen Shot 2015-10-08 at 10.19.47 AM

Idea: Java has its own Stack class, extending from Vector. Methods are push, pop, peek, empty, search.

When pushing the elements from stack 1 to stack 2, the pop & push operation combination rightly fits the correct sequence of joining elements from two stacks.

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