All Questions
6 questions
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 ...
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 ...
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 ...
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.
...
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 ...
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, ...