1 / 36
文档名称:

软件工程基础实验报告.doc

格式:doc   大小:677KB   页数:36页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

软件工程基础实验报告.doc

上传人:63229029 2017/10/23 文件大小:677 KB

下载得到文件列表

软件工程基础实验报告.doc

文档介绍

文档介绍:线性表的基本运算
班级: 姓名:实训成绩:□□批改教师签名:
一、实训学时:2学时
二、实训目的:
理解线性表的概念,掌握线性表的存储方法以及建立在该存储方法上的各种线性表算法,并用C/C++调试实现。
三、实训原理:
线性表是一种数据结构,它有多种存储方法,不同存储方法对应的线性表算法都有着相同的功能和不同的实现。学生实验时,线性表的存储结构可以通过数组和链表来实现,而线性表的各种算法则就是为实现相同功能而进行的数组或链表操作。
四、实训设备:
一台可以建立C/C++语言程序调试环境的个人计算机。
五、主要实训内容及编程:
1、线性表的各种存储结构的实训(用C/C++语言描述,用实训过程中的实训内容填写,实训过程中检查)。
相关线性表实训的前提必须使学生掌握并理解线性表的概念,并搞清楚什么是数据结构。数据结构不仅仅与数据的存储结构有关,同时与相关存储结构的算法有关。数据结构=数据的结构+算法。所以,线性表的存储结构十分重要。当然,线性表的存储结构有许多种,比如数组、链表等。下面给出一例:
#define ListSize 20
//List structure
typedef int DataType; //DataType的类型可根据实际情况而定,这里假设为int
typedef struct{
DataType data[ListSize]; //向量data用于存放表结点
int length; //当前的表长度
}seqList;
2、基于某种线性表存储结构给出线形表操作的各种算法实训(用C/C++语言描述,用实训过程中的实训内容填写,实训过程中检查检查)。
#include <>
#include <>
#define ListSize 20
//List structure
typedef int DataType; //DataType的类型可根据实际情况而定,这里假设为int
typedef struct{
DataType data[ListSize]; //向量data用于存放表结点
int length; //当前的表长度
}seqList;
//menu
void menu(){
printf("\nCreate and Init a list: -> 1\n");
printf("Get the length: -> 2\n");
printf("Get the ith node: -> 3\n");
printf("Find the node =x: -> 4\n");
printf("Insert the node x: -> 5\n");
printf("Delete the node x: -> 6\n");
printf("Your choice is: "); }
//Create and init a list
seqList* Init_seqlist(){
// int num;
int i=0;
seqList *list;
list=(seqList *)malloc(sizeof(seqList));

//从键盘输入
/*
printf("please input the seq number:");
scanf("%d",&num);
while(num!=-1){list->data[i++]=num;
scanf("%d",&num);}
list->data[i]=-1;
list->length=--i;
*/
//默认值
for(i=0;i<10;i++)
list->data[i]=i*10;
list->data[i]=-1;
list->length=i;
return list; }
//output the list
void output_seqlist(seqList *list)
{
int i=0;
printf("The sequence is: ");
while(list->data[i]!=-1)
printf("%d ",list->data[i++]);
printf("\n");
}
//get length of the list
int length_seqlist(seqList *list)
{
return list->length;
}
//get the node of i in the list
void getnode_seqlist(seqList *list)
{
int i;
printf("i=");
scan