快速排序_C语言_数组
快速排序_C语言_数组
#include <stdio.h>
void quickSort(int *, int, int);
int searchPos(int *, int, int);
int main(int argc, const char * argv[]) {
//定义乱序数组
int a[10] = {9, 3, 4, 6, 1, 2, 7, 8, 5, 0};
//排序前输出:
printf("乱序:\n");
for (int i = 0; i < 10; i++) {
printf("%d ",a[i]);
}
printf("\n\n");
//排序
quickSort(a, 0, 10);
//排序后输出:
printf("顺序:\n");
for (int i = 0; i < 10; i++) {
printf("%d ",a[i]);
}
printf("\n");
return 0;
}
void quickSort(int *a, int low, int height) {
int pos;
if (low < height) {
pos = searchPos(a, low, height);
quickSort(a, low, pos - 1);
quickSort(a, pos + 1, height);
}
}
int searchPos(int *a, int low, int height) {
int val = a[low];
while (low < height) {
while (low < height && a[height] > val) {
height --;
}
a[low] = a[height];
while (low < height && a[low] < val) {
low ++;
}
a[height] = a[low];
}
a[low] = val;
return low;
}
快速排序_C语言_数组的更多相关文章
- 选择排序_C语言_数组
选择排序_C语言_数组 #include <stdio.h> void select_sort(int *); int main(int argc, const char * argv[] ...
- 插入排序_C语言_数组
插入排序_C语言_数组 #include <stdio.h> void insertSort(int *); int main(int argc, const char * argv[]) ...
- 冒泡排序_C语言_数组
冒泡排序_C语言_数组 #include <stdio.h> //冒泡排序 小->大 void sort(int * pArray, int len); int main(int a ...
- 温故而知新_C语言_递归
递归. 是的,差不多就是这种感觉.上面就是类似递归的显示表现. 2017 10 24更新: 递归这个问题放了很久.也没有写.大概是自己还没有好好理解吧. 在这里写下自己理解的全部. 一 何为递归. 字 ...
- 温故而知新_C语言_前缀++(--)和后缀++(--)
前缀++(--)和后缀++(++)是有区别的. 再单独使用的时候是没有区别的,都是自身递增或者递减1. 但是综合使用起来会一样吗? 下面的例子都是++,替换成--也是一样,道理都是一样的. 请先看下面 ...
- 数据结构_C语言_二叉树先序、中序、后序遍历
# include <stdio.h> # include <stdlib.h> typedef struct BiTreeNode { char data; struct B ...
- 数据结构_C语言_单链表
# include <stdio.h> # include <stdbool.h> # include <malloc.h> typedef int DataTyp ...
- 【书籍下载链接】_1_第一轮_C语言书籍
各位朋友,如果您觉得下载的电子书,看的还可以,请购买纸质版的图书,如果您觉得 您下载的书,不值得一看请在下载后直接删除. Windows汇编:http://dl.vmall.com/c0jk1v970 ...
- 2.2 C语言_实现数据容器vector(排序功能)
上一节我们说到我们己经实现了一般Vector可以做到的自动扩充,告诉随机存取,那么现在我们需要完成vector的一个排序的功能. 排序算法我们网上一百度哇~~!很常见的就有8大排序算法: 1.选择排序 ...
随机推荐
- javaweb九大个内置对象,四大域
9个内置对象如下: 1.session对象:会话对象 当客户端第一次访问服务器的页面时,web服务器会自动为该客户端创建一个session对象并分配一个唯一的id号 常常用它来在多个页面间共享数据,如 ...
- Csharp:asp.net CheckBoxList databind
/// <summary> /// CheckBoxList數據源 /// 塗聚文 /// 20130705 /// /// </summary> private void s ...
- Html5的localStorage与sessionStorage五种循序渐进的使用方法
需求:本地记录用户上次输入的内容 使用关键技术:localStorage 第一步:使用jQuery的普通写法 1.JS代码 // 获取window的localStorage对象 var localS ...
- 提交自己的包到 npm 中
npm npm全称Node Package Manager,是node.js的模块依赖管理工具.使用github管理NPM包的代码,并定期提交至NPM服务器:npm官网 提交自己开发的NPM包 创建p ...
- Javascript 自定义输出
缘由 前段时间再看了一些javascript的学习资料,也写的一些demo,在输出的时候一般都用alert,但这个方法会打断函数运行,用起来不是很好.还有就是console.log这个方法,这种方法原 ...
- .NET开源工作流RoadFlow-表单设计-数据表格
数据表格即在表单中显示一个table,该table数据可以来自任意自定义的来源: 数据类型:指定表格的数据源类型 1.datatable,即.net中的System.Data.DataTable 2. ...
- Oracle 修改任何用户的密码
1.通过sys用户以sysdba身份登陆: 2.修改用户密码: alter user 用户名 identified by 密码; 比如修改system的密码为 manager : alter use ...
- 【Leetcode】【Easy】Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Zookeeper的集群配置和Java测试程序
Zookeeper是Apache下的项目之一,倾向于对大型应用的协同维护管理工作.IBM则给出了IBM对ZooKeeper的认知: Zookeeper 分布式服务框架是 Apache Hadoop 的 ...
- 查看锁定的session信息脚本
查看当前被阻塞的对象和锁信息SELECT DISTINCT s1.inst_id BlockingInst, s1.sid BlockingSid, s1.seri ...