实验二 线性表综合实验之《静态链表》
来源:互联网 发布:qq管家软件搬家 编辑:程序博客网 时间:2024/05/21 22:39
实验二 线性表综合实验之《双链表》
一.实验目的
巩固线性表的数据结构的存储方法和相关操作,学会针对具体应用,使用线性表的相关知识来解决具体问题。
二.实验内容
建立一个由n个学生成绩的顺序表,n的大小由自己确定,每一个学生的成绩信息由自己确定,实现数据的对表进行插入、删除、查找等操作。分别输出结果。
要求如下:
1)用顺序表来实现。
2)用单链表来实现。
3)用双链表实现。
4)用静态链表实现。
5)用间接寻址实现。
三.实验报告
1、代码
#includeusing namespace std;const int MaxSize=100;template struct SNode{T data;int next; //假指针};template class SList{public:SList();SList(T a[],int n);int Length();T Get(int i);int Locate(T x);void Insert(int i,T x);T Delete(int i);void PrintList();private:SNode S[MaxSize];int first,avail;};//遍历操作template void SList ::PrintList(){int p;p=S[first].next; //使其指向第一个元素while(p!=-1){cout< int SList::Length(){int p,count=0;p=S[first].next; //使其指向第一个元素while(p!=-1){p=S[p].next; //指针后移count++;}return count;}//按位查找template T SList ::Get(int i){int p,count=1;p=S[first].next;while(p!=-1&&countint SList ::Locate(T x){int p,count=1;p=S[first].next;while(p!=-1){if(S[p].data==x) return count;p=S[p].next;count++;}return 0;}//插入数据,在p后面插入template void SList ::Insert(int i,T x){int p,q,count=0;p=first;while(S[p].next!=-1&&count T SList ::Delete(int i){T x;int p,q,count=0;p=first;while(S[p].next!=-1&&count SList ::SList(){first=0;avail=1;S[0].next=-1; //头结点无后续结点for(int i=0;i SList ::SList(T a[],int n){int p;if(n>MaxSize||a<=0) throw"错误";first=0;avail=1;S[0].next=avail;for(int i=0;i SL(arr,5); //install an objectcout<<"\n 静态链表"< >tab; switch(tab) { case 1: {cout<<"1.输出表:"; SL.PrintList();cout< >loc; x=SL.Get(loc);cout <<"The number is:"< >x; loc=SL.Locate(x); cout<<"The number's location is:"< >loc; cout<<"Please input the insert num:"; cin>>x; SL.Insert(loc,x);cout< >loc; x=SL.Delete(loc);cout<
2、调试结果
①、遍历操作及输出总学生人数
②、按位查找操作
③、按值查找操作
④、插入操作
⑤、删除操作
阅读全文
0 0
- 实验二 线性表综合实验之静态链表
- 实验二 线性表综合实验之《静态链表》
- 实验二 线性表综合实验之《静态链表》
- 实验二 线性表综合实验(静态链表)
- 线性表综合实验之静态链表的实现
- 实验二 线性表综合实验之顺序表
- 实验二 线性表综合实验之《顺序表》
- 实验二 线性表综合实验之单链表
- 实验二 线性表综合实验之双链表
- 实验二 线性表综合实验之间接寻址
- 实验二 线性表综合实验之《单链表》
- 实验二 线性表综合实验之《双链表》
- 实验二 线性表综合实验之《间接寻址》
- 实验二 线性表综合实验之《单链表》
- 实验二 线性表综合实验之《双链表》
- 实验二 线性表综合实验之《间接寻址》
- 《数据结构》实验二 线性表综合实验
- 实验二线性表综合实验
- MySQL 性能监控4大指标——第二部分
- Ubuntu14.04下安装VMware (for linux)
- windows下使用maven编译spark源码
- 编写可测试的JavaScript代码
- 欢迎使用CSDN-markdown编辑器
- 实验二 线性表综合实验之《静态链表》
- 通过泛型写一个通用的单例
- 第三章
- java TCP、UDP笔记
- E 绝对半径2051 最长的连续相同序列的长度
- hdu 2804 先打表找规律
- [境内法规]中国人民银行令(2010)第2号--非金融机构支付服务管理办法
- maven构建Scala程序,实现spark的wordcount
- C++第一次培训