zoukankan
html css js c++ java
快速排序(QuickSort)用C# 实现的小例子
class
QuickSort
{
public
void
Sort(
int
[] data,
int
start,
int
end)
{
if
(start
>=
end)
return
;
if
(start
+
1
==
end)
{
if
(data[start]
>
data[end])
Swap(data, start, end);
return
;
}
int
indexL
=
start
+
1
, indexR
=
end;
while
(indexL
<
indexR)
{
//
Get from left
while
(indexL
<=
end
&&
data[start]
>=
data[indexL])
indexL
++
;
//
Get from right
while
(indexR
>
start
&&
data[start]
<
data[indexR])
indexR
--
;
if
(indexL
<
indexR)
{
Swap(data, indexR, indexL);
}
}
if
(indexL
-
1
!=
start)
Swap(data, start, indexL
-
1
);
Sort(data, start, indexL
-
2
);
Sort(data, indexL, end);
}
private
void
Swap(
int
[] data,
int
x,
int
y)
{
data[x]
=
data[x]
+
data[y];
data[y]
=
data[x]
-
data[y];
data[x]
=
data[x]
-
data[y];
}
}
文章首发
查看全文
相关阅读:
python 返回函数的使用
你的服务器还在裸奔吗?
云计算产品vSwitch原理
网卡创建Bond
UI自动化框架介绍
常用底层linux命令
Linux Bridge基本概念
磁盘格式化及设置自动挂载
Linux vi文本编辑器常用命令
MySQL5.7安装方式
原文地址:https://www.cnblogs.com/skywind/p/1131612.html
最新文章
scrapy 的response 的相关属性
记一次 php-fpm 连接 nginx 的错误。
docker 存储驱动(storage driver)知识总结
linux 关于 环境变量
关于邮件服务器的原理
关于dns服务工作的原理,和配置的细节理解。
二,zabbix与php的一些问题
Docker 进入容器的几种方式
Docker和k8s的区别与介绍
docker 私有仓库搭建
热门文章
Docker 私有仓库push
k8s node节点剔除与增加
k8s集群pod状态分析
CentOS安装PostgreSQL
centos下 yum快速安装maven
Kubernetes Logs 如何获取kube-system pod的日志
Gitlab部署到K8S上
MYSQL出现1251 client does no support authentic错误
centos7下安装python3.6(今天在百度云上安装)
ubuntu1~16.04.9 下安装python3.6 详细教程(在腾讯云服务器上安装实例)
Copyright © 2011-2022 走看看