C_数据结构_快速排序
# 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_数据结构_快速排序的更多相关文章
- c_数据结构_图_邻接表
课程设计------邻接表 图的遍历实现课程设计:https://files.cnblogs.com/files/Vera-y/图的遍历_课程设计.zip #include<stdio.h> ...
- C_数据结构_链表的链式实现
传统的链表不能实现数据和链表的分离,一旦数据改变则链表就不能用了,就要重新开发. 如上说示:外层是Teacher,里面小的是node. #ifndef _MYLINKLIST_H_ #define _ ...
- c_数据结构_队的实现
# 链式存储#include<stdio.h> #include<stdlib.h> #define STACK_INIT_SIZE 100//存储空间初始分配量 #defin ...
- c_数据结构_栈的实现
#include<stdio.h> #include<stdlib.h> #define STACK_INIT_SIZE 100 #define STACKINCREMENT ...
- c_数据结构_链表
#include<stdio.h> #include<stdlib.h> #define ERROR 0 #define OK 1 #define OVERFLOW -2 ty ...
- c_数据结构_顺序表
#define OK 1 #define ERROR 0 #define OVERFLOW -2 #define LIST_INIT_SIZE 100 // 线性表存储空间的初始分配量 #define ...
- C_数据结构_走迷宫
#include <stdio.h> #include <conio.h> #include <windows.h> #include <time.h> ...
- C_数据结构_链式二叉树
# include <stdio.h> # include <malloc.h> struct BTNode { int data; struct BTNode * pLchi ...
- C_数据结构_递归A函数调用B函数
# include <stdio.h> int g(int); int f(int); int f(int n) { ) printf("haha\n"); else ...
随机推荐
- Android 发送自定义广播(标准和本地)
1.首先自定义一个广播接收器:MyBroadcastReceiver package example.com.mybroadcastreceiver; import android.content.B ...
- sqlserver 拆分
有表tb, 如下:id value----------- -----------1 aa,bb2 aaa,bbb,ccc欲按id,分拆value列, 分拆后结果如下:id value--------- ...
- linux 平均负载 load average 的含义【转】
文章来源: linux 平均负载 load average 的含义 load average 的含义 平均负载(load average)是指系统的运行队列的平均利用率,也可以认为是可运行进程的平均数 ...
- python基础 - 变量与运算符
变量与运算符 变量 定义一个变量 a = [1,2,3,4,5,6] print(a) # [1,2,3,4,5,6] 变量命名要求: 首字母不能是数字 只能包含字符数字下划线 不能是关键字 type ...
- 如何使用 eclipse进行断点 debug 程序
先给出一段程序,然后通过使用 eclipse 设置断点进行一步步操作看结果 package cn.debug.com; public class Demo18 { public static void ...
- mysqldump与innobackupex备份过程你知多少
mysqldump与innobackupex备份过程你知多少 测试库表创建(这里在同一个库下创建两个表,一个表为innodb引擎,一个为myisam引擎) root@localhost : (none ...
- 寒假集训——搜索 B - Sudoku
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream&g ...
- python五十八课——正则表达式(切割)
切割:split(regex,string):返回一个列表对象 import re str1='i love shenzhen so much' regex=r' +?' lt=re.split(re ...
- SQL的各种连接Join详解
SQL JOIN 子句用于把来自两个或多个表的行结合起来,基于这些表之间的共同字段. 最常见的 JOIN 类型:SQL INNER JOIN(简单的 JOIN).SQL LEFT JOIN.SQL ...
- 2018-2019-2 20165302程上杰 Exp6 信息搜集与漏洞扫描
1,实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 2.,实验内容 (1)各种搜索技巧的应用 (2)DNS IP注册信息的查询 (3)基本的扫描技术:主机发现.端口扫描.OS及服务版本探测. ...