# 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. 第三章 Hyper-V 2012 R2配置选项

    原书中的第二章 是介绍了下hyper-v的管理器和检查点的使用,导入导出虚拟机,所以我跳过了不高兴写,很简单.直接进入第三部分,介绍虚拟机的三个重要组成部分:CPU,内存,硬盘的配置选项. Hyper ...

  2. python基本数据类型 数字 和 字符串

    一.数字      int type可以查看数据类型 将字符串转换为数字: a=" b=int(a) print(type(a)) 以十六进制或者八进制或者二进制的形式转换为十进制: num ...

  3. 【Excel】SUMIF函数的兼容性

    兼容性非常强的两个函数 SUMIF() 说兼容性,当然得说SUMIF了. 来,我们先举个例子. 现有一个表格,算起来只有"科目划分"."发生额"两列内容,但是折 ...

  4. The resource configuration is not modifiable in this context.

    项目中使用了Jersey RESTful 框架, 更新代码后服务能正常起来, 在页面登录时验证码不显示 后台报错 java.lang.IllegalStateException: The resour ...

  5. Java用户名登录学生信息管理系统并对其进行增删改查操作

    package zzzzzzzz; import java.io.*;//作者:凯鲁嘎吉 - 博客园//http://www.cnblogs.com/kailugaji/ public class T ...

  6. 什么是Java序列化?如何实现序列化?

    一.什么是序列化: 序列化理解成“打碎”是可以的,不过在书本上的名词就是将对象转换成二进制. 二.在java中如何实现序列化: 首先我们要把准备要序列化类,实现 Serializabel接口 例如:我 ...

  7. 【TJOJI\HEOI2016】求和

    [TJOI/HEOI2016]求和 这题好难啊!! 斯特林数+NTT. 首先我们将第二类斯特林数用容斥展开,具体原理不解释了. \(\displaystyle S(i,j)=\frac{1}{j!}\ ...

  8. mysql函数之截取字符串

    文章摘取自http://www.cnblogs.com/zdz8207/p/3765073.html 练习截取字符串函数(五个) mysql索引从1开始 一.mysql截取字符串函数 1.left(s ...

  9. C++反转单链表

    单链表 /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; ...

  10. ASP.NET 文件操作类

    1.读取文件 2.写入文件 using System; using System.Collections.Generic; using System.IO; using System.Linq; us ...