Write a C program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to write this program: Push | Pop | Top | IsEmpty | IsFull The algorithm is O(N^2) and appears below. Do we have any other better solution which is less than O(n * n) ?
void sort_stack(Stack * src, Stack * dest) { while (!src->IsEmpty()) { Int tmp = src->Pop(); while(!dest->IsEmpty() && dest->Top() > tmp) { src->Push(dest->Pop()); } dest->Push(tmp); } } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.