0

# include<bits/stdc++.h>

using namespace std;

int number[100005];

void quicksort(int left, int right)
{
if(left >= right)
return;

``````int i,j,key;
i = left;
j = right;
key = number[left];

while(i != j)
{
while(number[j] >= key && i < j)
j--;

while(number[i] <= key && i < j)
i++;

if(i < j)
swap(number[i], number[j]);

}

number[left] = number[i];
number[i] = key;
quicksort(left, i-1);
quicksort(i+1, right);
``````

}

int main()
{
int n;

``````scanf("%d",&n);
for(int i = 1; i <= n; i++)
scanf("%d",&number[i]);

quicksort(1, n);
for(int i = 1; i <= n; i++)
printf("%d ",number[i]);
return 0;
``````

}

# include <bits/stdc++.h>

using namespace std;

void quick_sort(int nums[],int low,int high)
{
if(low>=high)
{
return;
}

``````int l=low;
int r=high;
int tmp=nums[l];
while(l<r)
{
while(nums[r]>tmp&&l<r)
{
r--;
}
while(nums[l]<=tmp&&l<r)
{
l++;
}
if(l<r)
{
swap(nums[l],nums[r]);
}
}
swap(nums[low],nums[r]);
quick_sort(nums,low,l-1);
quick_sort(nums,l+1,high);
``````

}

int main()
{
int n,a[100005];
cin>>n;
for(int i=0;i<n;++i)
{
scanf("%d",a+i);
}
random_shuffle(a,a+n);//随机乱序
quick_sort(a,0,n-1);
for(int i=0;i<n;++i)
{
printf("%d ",a[i]);
}
return 0;
}

goalltheway | 初学一级 | 园豆：121

0

https://q.cnblogs.com/q/127456/

Conan-jine | 小虾三级 |园豆：1271 | 2020-08-08 20:14

goalltheway | 园豆：121 (初学一级) | 2020-08-08 20:22

@goalltheway: 可以看看这

Conan-jine | 园豆：1271 (小虾三级) | 2020-08-08 20:25

@Conan-jine: 感谢

goalltheway | 园豆：121 (初学一级) | 2020-08-08 20:25

@Conan-jine: 编译器换了一个，预览以后还那样，，我这是这样的，没找到插入代码

goalltheway | 园豆：121 (初学一级) | 2020-08-08 20:40

@goalltheway: 在这改吧，我用的tiny

Conan-jine | 园豆：1271 (小虾三级) | 2020-08-08 20:42

@Conan-jine:

goalltheway | 园豆：121 (初学一级) | 2020-08-08 20:47

@goalltheway: 点击左边的常用选项

Conan-jine | 园豆：1271 (小虾三级) | 2020-08-08 22:18

@Conan-jine: 欧克

goalltheway | 园豆：121 (初学一级) | 2020-08-09 14:20

您需要登录以后才能回答，未注册用户请先注册