首页 > 代码库 > int 与 int *
int 与 int *
#include <iostream>
using namespace std;
int QKPass(int* , int , int); //若声明为 int QKPass(int, int, int); 会显示错误
void QKSort(int a[], int low, int high){
int pos;
if(low < high){
pos = QKPass(a, low, high);
QKSort(a, low, pos - 1);
QKSort(a, pos + 1, high);
}
}
int QKPass(int *a, int low, int high){
int x = a[low];
while(low < high){
while(low < high && a[high] >= x)
high--;
if(low < high){
a[low] = a[high];
low++;
}
while(low < high && a[low] <= x)
low++;
if(low < high){
a[high] = a[low];
high--;
}
}
a[low] = x;
return low;
}
int main(){
int n, a[100];
int i, j, t;
cin >> n;
for(i = 1; i <= n; i++)
cin >> a[i];
QKSort(a, 1, n);
for(i = 1; i <= n; i++)
cout << a[i] << " ";
return 0;
}
int 与 int *