文档详情

数据结构实验五..doc

发布:2017-01-26约字共13页下载文档
文本预览下载声明
实验五 查找与排序 实验课程名: 数据结构与算法 专业班级: 学号: 姓名: 实验时间: 实验地点: 指导教师: 一、实验目的和要求 1、掌握查找的不同方法,并能用高级语言实现查找算法。 2、熟练掌握顺序表的查找方法和有序顺序表的折半查找算法。 3、掌握常用的排序方法,并能用高级语言实现排序算法。 4、深刻理解排序的定义和各种排序方法的特点,并能加以灵活运用。 5、了解各种方法的排序过程及依据的原则,并掌握各种排序方法的时间复杂度的分析方法。 二、实验内容 (一).任务一(1):顺序表的顺序查找 完成下列程序,该程序实现高考成绩表(如下表所示)的顺序查找,在输出结果中显示查找成功与查找不成功信息。 准考证号 姓名 各科成绩 总分 政治 语文 外语 数学 物理 化学 生物 179328 何芳芳 85 89 98 100 93 80 47 592 179325 陈红 85 86 88 100 92 90 45 586 179326 陆华 78 75 90 80 95 88 37 543 179327 张平 82 80 78 98 84 96 40 558 179324 赵小怡 76 85 94 57 77 69 44 502 (1)源代码如下: #includestring.h #includectype.h #includemalloc.h // malloc()等 #includelimits.h // INT_MAX等 #includestdio.h // EOF(=^Z或F6),NULL #includestdlib.h // atoi() #includeio.h // eof() #includemath.h // floor(),ceil(),abs() #includeprocess.h // exit() #includeiostream.h // cout,cin // 函数结果状态代码 #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 // #define OVERFLOW -2 因为在math.h中已定义OVERFLOW的值为3,故去掉此行 typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等 typedef int Boolean; // Boolean是布尔类型,其值是TRUE或FALSE #define MAX_LENGTH 100 #includestring.h #includectype.h #includemalloc.h // malloc()等 #includelimits.h // INT_MAX等 #includestdio.h // EOF(=^Z或F6),NULL #includestdlib.h // atoi() #includeio.h // eof() #includemath.h // floor(),ceil(),abs() #includeprocess.h // exit() #includeiostream.h // cout,cin // 函数结果状态代码 #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 // #define OVERFLOW -2 因为在math.h中已定义OVERFLOW的值为3,故去掉此行 typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等 typedef int Boolean; // Boolean是布尔类型,其值是TRUE或FALSE #define N 5 // 数据元素个数 #define EQ(a,b) ((a)==(b)) #define LT(a,b) ((a)(b)) #define LQ(a,b) ((a)=(b)) typedef long KeyType; // 设关键字域为长整型 #define key number // 定义关键字为准考证号 struct ElemType // 数据元素类型(以教科书图9.1高考成绩为例) { long number; // 准考证号,与关键字类型同 char name[9]; // 姓名(4个汉字加1个串结束标
显示全部
相似文档