[Q]Sorting

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
zizi
New poster
Posts: 7
Joined: Fri Jan 30, 2004 4:51 am

[Q]Sorting

Post by zizi »

Is there an algo to sort a sequence using only two stacks (with Push() and Pop()method ). Pls help me.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

If I think correct not all sequences are possible to sort using two stacks.

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

Post by Riyad »

hey ,
it is possible to sort a sequence using two stacks and 2 extra variables . it is very easy to implement bubble sort using only 2 stacks and 2 variables .but to implement it with only 2 stacks [not using any temporary variables ] is impossible . so if u r need , can allow two extra variable i can get the algo for u ......
Bye
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Ya, with a constant number of extra variables, 2 stacks is, after all, just a Turing machine, so of course you can sort.. =)
Post Reply

Return to “Algorithms”