Write a program to sort a stack in ascending order.
Thought:
Use another stack r & the original stack is s.
while(s is not empty) {
val = pop from s
while (val is smaller than peeking r) {
push to s(pop from r)
}
push val to r
}
No comments:
Post a Comment