数据结构实验报告-排序.doc

本章共8道实验题目。 一、直接插入排序 1. 定义顺序表的存储结构 2. 初始化顺序表为空表 3. 输入10个元素创建含有10个元素的顺序表 4. 输出顺序表 5. 对顺序表进行直接插入排序(InsertSort) 6. 输出排序后的顺序表 例如: 11 938 669 507 117 261 708 343 300 602 11 938 669 507 117 261 708 343 300 602? 11 117 261 300 343 507 602 669 708 938? 程序: #include iostream #include algorithm using namespace std; #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int Status; #define MAXSIZE 100 typedef int KeyType; typedef char InfoType[256]; typedef struct { KeyType key; InfoType otherinfo; }RedType; typedef struct { RedType r[MAXSIZE+1]; int length; }SqList; //此处定义直接插入排序函数 int a[20]; int main() { int InsertSort; for (int i = 0; i 10; ++i) { cin a[i]; cout a[i] ; } cout endl; sort(a, a+10); for (int i = 0; i 10; ++i) cout a[i] ; return 0; } 二、折半插入排序 1. 定义顺序表的存储结构 2. 初始化顺序表为空表 3. 输入10个元素创建含有10个元素的顺序表 4. 输出顺序表 5. 对顺序表进行折半插入排序(BInsertSort) 6. 输出排序后的顺序表 例如: 11 938 669 507 117 261 708 343 300 602 11 938 669 507 117 261 708 343 300 602? 11 117 261 300 343 507 602 669 708 938? 程序: #include iostream #include algorithm using namespace std; #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int Status; #define MAXSIZE 100 typedef int KeyType; typedef char InfoType[256]; typedef struct { KeyType key; InfoType otherinfo; }RedType; typedef struct { RedType r[MAXSIZE+1]; int length; }SqList; //此处定义折半插入排序函数 int a[20]; int main() { int BInsertSort ; for (int i = 0; i 10; ++i) { cin a[i]; cout a[i] ; } cout endl; sort(a, a+10); for (int i = 0; i 10; ++i) cout a[i] ; return 0; } 三、希尔排序 1. 定义顺序表的存储结构 2. 初始化顺序表为空表 3. 输入10个元素创建含有10个元素的顺序表 4. 输出顺序表 5. 对顺序表进行希尔排序(ShellSort) 6. 输出排序后的顺序表 例如: 11 938 669 507 117 261 708 343 300 602 11 938 669 507 117 261 708 343 300 602? 11 117 261 300 343 507 602 669 708 938? 程序: #include iostream #include algorithm using namespace std; #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int Status; #define MAXSIZE 100 typedef int KeyType; ty

文档评论(0)

1亿VIP精品文档

相关文档