# 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. Linux源码解析-内核栈与thread_info结构详解

    1.什么是进程的内核栈? 在内核态(比如应用进程执行系统调用)时,进程运行需要自己的堆栈信息(不是原用户空间中的栈),而是使用内核空间中的栈,这个栈就是进程的内核栈 2.进程的内核栈在计算机中是如何描 ...

  2. Linux 小知识翻译 - 「Linux」和「发行版」之间的关系

    「Linux」本来指的仅仅是内核.5年之前大多都是这么认为的,但是最近不这么说了. 最近一般都说「Linux」是个 OS,这里的OS,不仅仅是内核,而是指电脑的整体环境(除了内核,还包括一些外围的软件 ...

  3. css实现不定高度的元素垂直居中问题

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. PostgreSQL9.6+PostGIS2.3学习笔记(一)导入shp文件

    一. 建库以及准备工作:(使用pgAdmin4直接建库) 打开pgAdmin4,如下图所示create–>Database 输入database的名字,如下图,输入完成即可选择save进行保存. ...

  5. github拓展,以及ModelForm的使用

    github - git  init/add/commit/reset/log/status/stash pop/checkout/branch    新入职到公司,地址:   git clone h ...

  6. 全文索引搜索whoosh

    问题 Whoosh是python中解决索引查找的模块,在讨论索引查找的文章已经对有关索引查找进行了阐述,此处具体说明Whoosh模块的应用. 思路说明 Whoosh的安装 这里有具体内容(链接被被阉割 ...

  7. (3)HomeAssistant 连接MQTT

    整体说明 1 自己在阿里云上搭建MQTT服务器 2 自己笔记本电脑windos10搭建HASS,配置参数连接阿里云服务器 3 手机下载MQTT调试助手,当测试端 4手机当终端---阿里云MQTT--- ...

  8. Codeforces Round #553 (Div. 2) D. Stas and the Queue at the Buffet 贪心+公式转化

    题意 给出n个pair (a,b) 把它放在线性序列上 1--n 上 使得  sum(a*(j-1)+b*(n-j))  最小 思路 :对式子进行合并 同类项 有:    j*(a-b)+  (-a+ ...

  9. day16 Python filter函数

    前戏 movie_people = ["alex","charon","pluto","liu","sb&qu ...

  10. (转)Docker磁盘垃圾清理

    文章转自https://mp.weixin.qq.com/s/S8ZjGZF8oLC8c1JRnkE5yw?tdsourcetag=s_pctim_aiomsg 1.整体分析 对于Docker来说,存 ...