Knowsh.com

Write a program to Sort a stack such that the smallest items are on the top

http://www.knowsh.com

Write a program to Sort a stack such that the smallest items are on the top. You can use additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push, pop, peek, isEmpty.

We have used two additional Stacks for that. One is forward Stack to store the items in the sorted way such that greatest item is at the top, from the given stack. Another is backward Stack to store the sorted items in such a way that lowest item is at the top, from the forward stack.

http://knowsh.com/Notes/NotesSearch/NotesDetail/140222/Program-To-Sort-A-Stack-Using-Additional-Data-Structure

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