How to sort a number of elements in stack1 ordering with the smallest is on the top of the stack, and you can use temporary stack 2??
What is the idia and time complexity of your algorithm?

Can any one push me to idea?:eek:

I can do it with 3 temporary stack like a Tower of Hanoi :!:

Recommended Answers

All 4 Replies

hey it sounds a very interesting question if you are not allowed to use anything apart from two Stack

Tell me ARe we allowed to use temp varaibe here

You can use a temp Stack 2 only.

But you can try with a temp variable

Think about the only operations you can perform between two stacks if you have no extra memory, and you're sitting on top of the answer.

And if you think about it, a pair of stacks is quite similar in concept to a pointer in the middle of an array. One stack represents moving downwards in the array, and the other represents moving upwards.

Member Avatar for iamthwee

With two stacks...erm... aren't some particular permutations unsortable so to speak... series or parallel stacks?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.