#include<stdio.h>
#define MAXSIZE 10000
void QuickSort(int a
[],int lo
,int hi
);
int Partition(int a
[],int lo
,int hi
);
void swap(int a
[],int b
,int c
);
void Output(int a
[],int n
);
int main()
{
int n
;
int a
[MAXSIZE
];
int i
;
scanf("%d",&n
);
for(i
=0;i
<n
;i
++){
scanf("%d",&a
[i
]);
}
QuickSort(a
,0,n
-1);
Output(a
,n
);
return 0;
}
void QuickSort(int a
[],int lo
,int hi
)
{
int i
;
if(lo
>=hi
)return;
else{
i
=Partition(a
,lo
,hi
);
QuickSort(a
,lo
,i
-1);
QuickSort(a
,i
+1,hi
);
}
}
int Partition(int a
[],int lo
,int hi
)
{
int i
=lo
,j
=hi
;
int tmp
=a
[lo
];
while(i
!=j
){
while(i
<j
&&a
[j
]>=tmp
)j
--;
while(i
<j
&&a
[i
]<=tmp
)i
++;
swap(a
,i
,j
);
}
swap(a
,lo
,i
);
return i
;
}
void swap(int a
[],int b
,int c
)
{
int temp
;
temp
=a
[b
];
a
[b
]=a
[c
];
a
[c
]=temp
;
}
void Output(int a
[],int n
)
{
int i
;
for(i
=0;i
<n
;i
++){
printf("%d\n",a
[i
]);
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-40050.html