文档详情

实验五查找及排序讲解.doc

发布:2017-04-17约1.3万字共15页下载文档
文本预览下载声明
PAGE  PAGE 14 实验五 查找及排序 实验课程名: 数据结构与算法 一、实验目的及要求 1、掌握查找的不同方法,并能用高级语言实现查找算法。 2、熟练掌握顺序表的查找方法和有序顺序表的折半查找算法。 3、掌握常用的排序方法,并能用高级语言实现排序算法。 4、深刻理解排序的定义和各种排序方法的特点,并能加以灵活运用。 5、了解各种方法的排序过程及依据的原则,并掌握各种排序方法的时间复杂度的分析方法。二、实验内容 任务一:顺序表的顺序查找。 有序表的折半查找。 完成下列程序,该程序实现高考成绩表(如下表所示)的顺序查找,在输出结果中显示查找成功与查找不成功信息。 准考证号姓名各科成绩总分政治语文外语数学物理化学生物179328何芳芳858998100938047592179325陈红858688100929045586179326陆华78759080958837543179327张平82807898849640558179324赵小怡76859457776944502解答: (1)源代码:#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个串结束标志) int politics; // 政治 int Chinese; // 语文 int English; // 英语 int math; // 数学 int physics; // 物理 int chemistry; // 化学 int biology; // 生物 int
显示全部
相似文档