1035: Sorting an array
Memory Limit:128 MB
Time Limit:1.000 S
Judge Style:Text Compare
Creator:
Submit:38
Solved:19
Description
Write a C program to sort a list of N (N<=16384) integer numbers in ascending or descending order when the option is 1 or 2, respectively. The input is in the following form:
N op
a1 a2 a3 a4 ..... an
where N is the number of the element in the array to be given and an's are integers less than or equal to 65535. op is the option; 1 for ascending order and 2 for descending order.
N op
a1 a2 a3 a4 ..... an
where N is the number of the element in the array to be given and an's are integers less than or equal to 65535. op is the option; 1 for ascending order and 2 for descending order.
Input
10 1
66 4 85 93 68 76 74 39 66 17
66 4 85 93 68 76 74 39 66 17
Output
4 17 39 66 66 68 74 76 85 93
Sample Input Copy
5 1
15809 2582 15902 15682 7952
Sample Output Copy
2582 7952 15682 15809 15902
HINT
As sorting is a common technique in computer programming, mature algorithms are developed and easily accessed. In chapter 7 of curse EO1004(A) selection sort and merge sort are introduced.