快速排序_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.选择排序 ...
随机推荐
- mvc中RedirectToAction()如何传参?
今天在做一个功能的时,使用RedirectToAction()需要从这里传几个参数,从网上查了一下,这样解决.真好. Return RedirectToAction("Index" ...
- java字节码速查笔记
java字节码速查笔记 发表于 2018-01-27 | 阅读次数: 0 | 字数统计: | 阅读时长 ≍ 执行原理 java文件到通过编译器编译成java字节码文件(也就是.class文件) ...
- python调用其他文件的类和函数
在同一个文件夹下 调用函数 source.py文件: def func(): pass new.py文件: import source # 或者 from source import func 调用类 ...
- 对json缓存进行操作
var data={ id:1, name:"张三" } //存储缓存 var arrdata=[]; arrdata.push({id:data.id,name:data.nam ...
- iOS内存泄露统计
1.Value stored to 'xxx' during its initialization is never read // 对象声明之后根本就没有使用 只有赋值 2.Value stored ...
- Java入门到精通——框架篇之Spring源码分析Spring两大核心类
一.Spring核心类概述. Spring里面有两个最核心的类这是Spring实现最重要的部分. 1.DefaultListableBeanFactory 这个类位于Beans项目下的org.spri ...
- 【Mood-15】DailyBuild 1月
keywords: AsyncImageLoader universal-image-loader 2015-01-07 AsyncImageLoader:异步动态加载网络图片 类似listview ...
- matlab练习程序(生成黑白网格)
提供了两种生成方法,一个是自己编程实现,比较灵活:另一个是调用系统的checkerboard函数,似乎只能生成8*8网格. 至于用途,也许可以用来下国际象棋. 自己函数生成: 系统函数生成: 代码如下 ...
- Chrome+ProxySwitchySharp+Putty
好不容易写一个不编程的随笔了. 题目写出来,目的就已经很明确了,我就不详细解释原因了. 其实一年前多就已经配置成功了,写这篇随笔主要是给自己做一个备份,如果顺便能帮助其他人,也算功德无量了. 我就从最 ...
- SELECT s.* FROM person p INNER JOIN shirt s ON s.owner = p.id WHERE p.name LIKE 'Lilliana%' AND s.color <> 'white';
SELECT s.* FROM person p INNER JOIN shirt sON s.owner = p.idWHERE p.name LIKE 'Lilliana%'AND s.color ...