Sort all the stacks in this order:
Stack1 in alphabetic order by name
Stack2 in alphabetic order by Surname
Stack3 in Numeric order (descending) by marks obtained
The below algorithm can be used to sort all the three stacks:
declare a temporary stack say temporary_tack.
While (input_stack is NOT empty){
pop an item from the input_stack and name it as temp
while(temporary_tack is not empty and top of temporary_tack > temp){
pop from the temporary_tack and push it back to the input_stack.
push temp into the temporary_stack
}
}
input_stack = temporary_tack
Comments
Leave a comment