排序
排序分为:内排序,外排序
排序概念没什么好说的。
内排序
直接插入排序 折半插入排序 希尔排序 冒泡排序 快速排序 简单选择排序 堆排序 归并排序 基数排序
各种内排序的方法比较和选择 习题板块
外排序
外排序,我们课没学,看情况,以后我可能会自己补上去。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
//顺序表基本运算算法 #include <stdio.h> #define MAXL 100 //最大长度 typedef int KeyType; //定义关键字类型为int typedef char InfoType; typedef struct { KeyType key; //关键字项 InfoType data; //其他数据项,类型为InfoType } RecType; //查找元素的类型 void swap(RecType x,RecType y) //x和y交换 { RecType tmp=x; x=y; y=tmp; } void CreateList(RecType R[],KeyType keys[],int n) //创建顺序表 { for (int i=0;i<n;i++) //R[0..n-1]存放排序记录 R[i].key=keys[i]; } void DispList(RecType R[],int n) //输出顺序表 { for (int i=0;i<n;i++) printf("%d ",R[i].key); printf("\n"); } //----以下运算针对堆排序的程序 void CreateList1(RecType R[],KeyType keys[],int n) //创建顺序表 { for (int i=1;i<=n;i++) //R[1..n]存放排序记录 R[i].key=keys[i-1]; } void DispList1(RecType R[],int n) //输出顺序表 { for (int i=1;i<=n;i++) printf("%d ",R[i].key); printf("\n"); } |