incremental sort

closed account (oyA74iN6)
Given a stack, the task is to sort it such that the top of the stack has the greatest element.

Input:
The first line of input will contains an integer T denoting the no of test cases . Then T test cases follow. Each test case contains an integer N denoting the size of the stack. Then in the next line are N space separated values which are pushed to the the stack.

Output:
For each test case output will be the popped elements from the sorted stack.

Constraints:
1<=T<=100
1<=N<=100

Example(To be used only for expected output):
Input:
2
3
3 2 1
5
11 2 32 3 41

Output:
3 2 1
41 32 11 3 2

Explanation:
For first test case stack will be
1
2
3
After sorting
3
2
1

When elements popped : 3 2 1
Last edited on
when writing your comparison for the std sort routine, you can make it complicated...

in pseudo code:
a is less than b if uppercase(a.city) < uppercase(b.city)
if the above is equal, the
a is less than b if (a.time) < (b.time) //figure out how to compare the timestamps

etc. At the end of it all, your code should have prioritized the city comparison first, and when those are equal, figured out the time comparison instead.

Then just feed that to the sort routine, or add the comparison operator overload to your class and it should work.

Topic archived. No new replies allowed.