Skip to main content
The 2025 Developer Survey results are in. Explore insights into technology and tools, careers, community and more. View results.

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
580 views

Sort a stack using Java

This is my attempted solution to cracking the coding interview exercise 3.5. Looking for any feedback on coding style or the algorithm anywhere I can improve really. The problem specification is as ...
Average's user avatar
  • 851
4 votes
1 answer
2k views

Sort stack using two stacks

My program is supposed to sort a stack such that the smallest item are on the top. I can use a temporary stack, but you may not copy the elements into any other data structure. The program works ...
Stackimus Prime's user avatar
4 votes
1 answer
4k views

Sort a stack in descending order

Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a ...
saneGuy's user avatar
  • 373
3 votes
3 answers
3k views

Sort stack in ascending order

I am using two more helper stacks to sort. Kindly suggest improvements in terms of space and time. ...
Mosbius8's user avatar
  • 787
4 votes
2 answers
7k views

Sorting a Stack in ascending order

Here's my implementation of sorting a stack in ascending order. The problem statement is as follows : Write a program to sort a stack in ascending order (with biggest items on top). You may use at ...
Mayur Kulkarni's user avatar
5 votes
1 answer
5k views

Sort a stack in ascending order

Sort a stack in ascending order. You may only use one additional stack to hold items. Any comments on my solution? Worst case complexities: Memory complexity: O(n) Runtime complexity: O(n^2) Also, ...
giulio's user avatar
  • 743