(六十三)第 10 章 内部排序(插入排序)

示例代码

insertionSort.h

// 插入排序的实现头文件

#ifndef INSERTION_SORT_H
#define INSERTION_SORT_H

#include "errorRecord.h"

#define NUM 8
#define MAX_SIZE 20

#define EQUAL(a, b) ((a) == (b))
#define LESS_THAN(a, b) ((a) < (b))
#define LESS_OR_EQUAL(a, b) ((a) <= (b))

typedef int InfoType;
typedef int KeyType;

typedef struct {
	KeyType key;
	InfoType info;
} RecType;

typedef struct {
	RecType rec[MAX_SIZE + 1]; // 0 位置用作哨兵或闲置
	int length;
} SqList;

/*
	算法 10.1
	前置条件:list 非空
	操作结果:对顺序表 list 作直接插入排序
*/
Status InsertSort(SqList *list);

/*
	算法 10.2
	前置条件:list 非空
	操作结果:对顺序表 list 作折半插入排序
*/
Status BInsertSort(SqL

你可能感兴趣的:(#,数据结构(C语言版),数据结构,算法,散列表,哈希算法)