# 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. 合理配置SQLSERVER内存

    合理配置SQLSERVER内存 原文地址:https://www.cnblogs.com/lyhabc/archive/2012/09/28/2707857.html SQLSERVER是个很喜欢内存 ...

  2. 3.5Python数据处理篇之Numpy系列(五)---numpy文件的存取

    目录 目录: (一)以文本形式存取 1.说明: 2.语法解释: 3.实例(以.csv文件为例) 4.效果展示 (二)以任意的形式存取 1.说明: 2.语法解释: 3.实例(以.bat二进制文件为例) ...

  3. OutputStreamWriter与InputStreamReader(转换流)

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import jav ...

  4. 【BZOJ3529】数表

    数表 Description 有一张 n*m 的数表,其第i行第j列(1<=i<=n,1<=j<=m)的数值为能同时整除 i和j的所有自然数之和.给定a,计算数表中不大于a的数 ...

  5. CentOS 7下安装Python3.6.4

    CentOS 7下安装Python3.5 •安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-deve ...

  6. python五十六课——正则表达式(常用函数之findall)

    4).函数:findall(regex,string,[flags=0]): 参数: 和match.search一样理解 功能: 将所有匹配成功的子数据(子串),以列表的形式返回: 如果一个都没有匹配 ...

  7. kafka libjvm 报错

    kafka集群 kafka-0 出现报错信息 # # A fatal error has been detected by the Java Runtime Environment: # # SIGS ...

  8. metamask源码学习-ui/index.js

    The UI-即上图左下角metamask-ui部分,即其图形化界面 The MetaMask UI is essentially just a website that can be configu ...

  9. 【转】Kaggle注册问题-验证码和手机短信

    注册和登录Kaggle时验证码无法显示问题 参考:https://blog.csdn.net/zhuisaozhang1292/article/details/81529981 应用FQ软件需要时时关 ...

  10. PAT A1017 Queueing at Bank (25 分)——队列

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...