博客
关于我
快速排序
阅读量:225 次
发布时间:2019-02-28

本文共 577 字,大约阅读时间需要 1 分钟。

归并排序是每一次的递归调用会确定正确排序中的一个值。

然后这时只确定了个元素的位置。
再通过

fun(left,i-1);fun(i+1,right);

确定这个元素两边的正确排序的位置

#include 
using namespace std;int a[5005];int fun(int left,int right){ if(left >= right) return 0; int i = left; int j = right; int x = a[i]; while(i < j){ while(i < j && a[j] >= x) j--; if(i < j) a[i++] = a[j]; while(i < j && a[i] < x) i++; if(i < j) a[j--] = a[i]; } a[i] = x; fun(left,i-1); fun(i+1,right); return 0;}int main(){ int n; scanf("%d",&n); for(int i = 0;i < n;i++){ scanf("%d",a+i); } fun(0,n-1); for(int i = 0;i < n;i++){ printf("%d\n",a[i]); } return 0;}

转载地址:http://nfqp.baihongyu.com/

你可能感兴趣的文章
nacos服务注册流程
查看>>
Nacos服务部署安装
查看>>
nacos本地可以,上服务器报错
查看>>
Nacos注册Dubbo(2.7.x)以及namespace配置
查看>>
Nacos注册中心有几种调用方式?
查看>>
nacos注册失败,Feign调用失败,feign无法注入成我们的bean对象
查看>>
nacos源码 nacos注册中心1.4.x 源码 nacos源码如何下载 nacos 客户端源码下载地址 nacos discovery下载地址(一)
查看>>
nacos源码 nacos注册中心1.4.x 源码 spring cloud alibaba 的discovery做了什么 nacos客户端是如何启动的(二)
查看>>
nacos源码 nacos注册中心1.4.x 源码 如何注册服务 发送请求,nacos clinet客户端心跳 nacos 注册中心客户端如何发送的心跳 (三)
查看>>
Nacos源码分析:心跳机制、健康检查、服务发现、AP集群
查看>>