插入排序算法中的直接排序算法,折半插入排序算法,希尔排序算法。
这三个算法理解顺序:直接----->折半-------->希尔排序算法。
#include<stdio.h>
#include<stdlib.h>
#define N 10
typedef int KeyType; //定义关键字类型
typedef int DataType; //其他数据类型
typedef struct //记录数据结构
{
KeyType key; //关键字
DataType data; //其他数据
}RecType;
/* InitRec : 创建排序的结构体数组 */
void InitRec(RecType arr_Rec[],int a[], int n)
{
int i = 0;
for (i = 0; i < n; ++i)
{
arr_Rec[i].key = a[i]; //排序的数据
arr_Rec[i].data = 0;
}
}
/* ShowData: 递归方式顺序打印排序结构体数组的关键字 */
void ShowData(RecType arr_Rec[], int n)
{
if (n == 0) //到达末尾
{
printf("\n\n");
return;
}
else
{
printf(" %-5d", arr_Rec[0].key);
RecType *p;
p = arr_Rec;