-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1177.cpp
53 lines (44 loc) · 808 Bytes
/
P1177.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include<stdio.h>
using namespace std;
int map[100005];
int partion(int a[],int low,int high)
{
int temp = a[low];
while(high>low)
{
while(high>low&&a[high]>temp)
high--;
a[low] = a[high];
while(high>low&&a[low]<=temp)
low++;
a[high] = a[low];
}
a[low] = temp;
return low;
}
void sort(int a[],int low,int high)
{
if(low<high)
{
int pos = partion(a, low, high);
sort(a, low, pos - 1);
sort(a, pos + 1, high);
}
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n;i++)
{
scanf("%d",map+i);
}
sort(map, 1, n);
for (int i = 1; i <n;i++)
{
printf("%d ", map[i]);
}
printf("%d\n", map[n]);
return 0;
}