# include <stdio.h>

void QuickSort(int * a, int low, int high);
int FindPos(int * a, int low, int high); int main(void)
{
int a[] = {, , , , , };
int i; QuickSort(a, , ); //第二个参数表示第一个元素的下标,第三个参数表示最后一个元素的下标,表示把a[0]-a[5]进行排序 for (i=; i<; ++i)
printf("%d ", a[i]);
printf("\n"); return ;
} void QuickSort(int * a, int low, int high)
{
int pos; if (low < high)
{
pos = FindPos(a, low, high);
QuickSort(a, low, pos-);
QuickSort(a, pos+, high);
}
} int FindPos(int * a, int low, int high)
{
int val = a[low]; while (low < high)
{
while (low < high && a[high]>=val)
--high;
a[low] = a[high]; while (low<high && a[low]<=val)
++low;
a[high] = a[low];
} //终止while循环后low和high一定是相等的
a[low] = val; return low; //high可以改为low,但不能改为val,也不能改为a[low]和a[high]
}

C_数据结构_快速排序的更多相关文章

  1. c_数据结构_图_邻接表

    课程设计------邻接表 图的遍历实现课程设计:https://files.cnblogs.com/files/Vera-y/图的遍历_课程设计.zip #include<stdio.h> ...

  2. C_数据结构_链表的链式实现

    传统的链表不能实现数据和链表的分离,一旦数据改变则链表就不能用了,就要重新开发. 如上说示:外层是Teacher,里面小的是node. #ifndef _MYLINKLIST_H_ #define _ ...

  3. c_数据结构_队的实现

    # 链式存储#include<stdio.h> #include<stdlib.h> #define STACK_INIT_SIZE 100//存储空间初始分配量 #defin ...

  4. c_数据结构_栈的实现

    #include<stdio.h> #include<stdlib.h> #define STACK_INIT_SIZE 100 #define STACKINCREMENT ...

  5. c_数据结构_链表

    #include<stdio.h> #include<stdlib.h> #define ERROR 0 #define OK 1 #define OVERFLOW -2 ty ...

  6. c_数据结构_顺序表

    #define OK 1 #define ERROR 0 #define OVERFLOW -2 #define LIST_INIT_SIZE 100 // 线性表存储空间的初始分配量 #define ...

  7. C_数据结构_走迷宫

    #include <stdio.h> #include <conio.h> #include <windows.h> #include <time.h> ...

  8. C_数据结构_链式二叉树

    # include <stdio.h> # include <malloc.h> struct BTNode { int data; struct BTNode * pLchi ...

  9. C_数据结构_递归A函数调用B函数

    # include <stdio.h> int g(int); int f(int); int f(int n) { ) printf("haha\n"); else ...

随机推荐

  1. windows任务管理器怎么知道多个IIS网站进程分别对应哪个网站

    摘要: 1.IIS网站对应的进程名一般叫w3wp.exe (windows2008系统为例,其他类似) 2.windows默认的任务管理器只能看到多个同名的进程名w3wp.exe,没法区别分别对应哪个 ...

  2. dell r420 H310/H810阵列配置教程及常见问题

    进入H310/H810阵列卡BIOS界面 阵列卡管理快捷键 如何创建RAID0和RAID1和RAID5 阵列修复篇 Foreign(外来)状态的硬盘应如何处理 1.进入H310/H810阵列卡BIOS ...

  3. IDEA 如何查看一个类里面的所有方法

    快捷键:Alt+7

  4. 8.1Python面向对象编程(一)

    目录 目录 前言 (一)基本概念 ==1.面向过程与面向对象== ==2.类与对象== (二)类属性的相关操作 ==1.定义一个经典类== ==2.对象属性的操作== ==3.类属性的操作== ==4 ...

  5. parallels Desktop解决无法压缩硬盘的问题

    使用pd12新建的win7虚拟机仅仅使用了四十个G,但在本地硬盘中的体现却是占用了一百左右:尝试压缩提示: 无法编辑硬盘属性,因为该硬盘有一个或多个快照. 该硬盘属于某一带有一个或多个快照的虚拟机.请 ...

  6. mysqldump与innobackupex备份过程你知多少

    mysqldump与innobackupex备份过程你知多少 测试库表创建(这里在同一个库下创建两个表,一个表为innodb引擎,一个为myisam引擎) root@localhost : (none ...

  7. node爬虫扒小说

    Step 1:  万年不变的初始化项目,安装依赖 cnpm i express cheerio superagent superagent-charset async -S express 就不用多说 ...

  8. 接上篇elasticsecrchi 进行搜索及时提示,数据库以及后台代码

    -- ------------------------------ Table structure for articles-- ----------------------------DROP TA ...

  9. 使用HostAliases 添加pod 的/etc/hosts

    默认的pod 的/etc/hosts 无法自动数据 [root@master1 ~]# kubectl exec smsservice-5c7ff5f74-bc969 -n testihospital ...

  10. go标准库的学习-crypto/rand

    参考:https://studygolang.com/pkgdoc 导入方式: import "crypto/rand" rand包实现了用于加解密的更安全的随机数生成器. Var ...