内存超了,为什么
查看原帖
内存超了,为什么
863501
404744496xh楼主2023/1/9 15:53
#include<stdio.h>
int n,array[1000001];
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
void QuickSort(int low, int high) {
    int i = low; 
    int j = high;
    if(i >= j) {
        return;
    }
 
    int temp = array[(low+high)/2];
    while(i <= j) {
        while(array[j] > temp) {
            j--;
        }
	while(array[i] < temp) {
            i++;
        }
	if(i <= j) {
            swap(array+i, array+j);
            i++;
            j--;
        }
    }
    QuickSort( low, i);
    QuickSort( j, high);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&array[i]);
    QuickSort(1,n);
    for(int i=1;i<=n;i++) printf("%d ",array[i]);
}
2023/1/9 15:53
加载中...