实验二单链表的实现
来源:互联网 发布:淘宝红搜是什么意思 编辑:程序博客网 时间:2024/05/16 19:07
《数据结构》实验二:
线性表综合实验
一.实验目的
巩固线性表的数据结构的存储方法和相关操作,学会针对具体应用,使用线性表的相关知识来解决具体问题
二.实验内容
1.建立一个由n个学生成绩的顺序表,n的大小由自己确定,每一个学生的成绩信息由自己确定,实现数据的对表进行插入、删除、查找等操作。分别输出结果。
要求如下:
1)用顺序表来实现。
2)用单链表来实现。
3)用双链表实现。
4)用静态链表实现。
5)用间接寻址实现。
分开写程序,可以一个方法分别写一博客文章上交作业。
四.实验报告
1.在博客中先写上实习目的和内容,画出主要操作运算算法图,然后分别上传程序代码。插入调试关键结果截图。
2.单独写一个博文,比较总结线性表的几种主要存储结果。
单链表的实现
源代码:
#includeusing namespace std;const int M=100;struct Node{int data;Node *next;}; class LinkList //定义类SeqList {public:LinkList();LinkList(int a[],int n);~LinkList();int Length(); int Get(int i); void Insert(int i,int x); int Delete(int i); void PrintList(); private:Node *first;};LinkList::LinkList(){ first=new Node;first->next=NULL;}LinkList::LinkList(int a[],int n){ Node *r; Node *s; int i; first=new Node; r=first;for(i=0;i data=a[i];r->next=s;r=s;}r->next=NULL; }LinkList::~LinkList(){while(first!=NULL){ Node *q;q=first;first=first->next;delete q;}}int LinkList::Length() //表长 {Node *p;int count;p=first->next; count=0;while(p!=NULL){p=p->next;count++;}return count;}int LinkList::Get(int i) //按位查找 {Node *p;int count;p=first->next;count=1;while(p!=NULL&&countnext;count++;}if(p==NULL) throw"位置";else return p->data; }void LinkList::Insert(int i,int x) //插入 {Node *p;int count;p=first->next;count=0;while(p!=NULL&&count next;count++;}if(p==NULL) throw"位置";else{Node *s;s=new Node;s->data=x;s->next=p->next;p->next=s;} }int LinkList::Delete(int i) //删除 {Node *p;Node *q;Node *x;int count;p=first->next;count=0;while(p!=NULL&&count next;count++;}if(p==NULL||p->next==NULL)throw"位置"; else{q=p->next;x=q->next;p->next=q->next;delete q;return x->data;} }void LinkList::PrintList() //遍历操作 {Node *p;int i=0;p=first->next;while(p!=NULL){ i=i+1; cout<<"\t\t\t\t\t第"<data;cout< next;}}int main(){ int x,n,loc,len; cout<<"\t\t\t\t\t录入学生成绩信息"< >n;for(j=0;j >d[j];} LinkList List(d,n); while(1){cout< >x;cout< >loc;n=List.Get(loc);cout<<"\t\t\t\t\t该学生的成绩为:"< >loc;cout<<"\t\t\t\t\t输入学生成绩:";cin>>n;List.Insert(loc,n);cout<<"\t\t\t\t\t插入成功!"< >loc;cout<<"\t\t\t\t\t已删除的学生成绩:"<
1)录入学生成绩,输出学生人数:
2)输出学生成绩:
3)插入操作:
4)插入成功后输出学生成绩:
5)按位查找:
6)删除操作:
7)删除成功后输出学生成绩:
阅读全文
0 0
- 实验二单链表的实现
- 分片实验的实现
- 实验二 单链表的实现
- 实验二:单链表的实现
- 实验一:线性表实验-顺序表的实现
- 实验二:线性表实验-单链表的实现
- 爹地的实验:实验一: 数据结构实验一线性表的基本操作实现及其应用
- 用VC++实现FTP的实验
- JAVA多态性的实现-java实验报告
- cisco VLAN之间路由的实现实验
- 吐槽ECP设备实验实现的环境
- kmap的实现分析与实验
- 计通网实验的准备工作(C语言实现)
- 实验三:顺序栈的实现
- 实验三:链队列的实现
- 实验三:顺序栈的实现
- 实验四【1.字符串的实现】
- 实验二~顺序表的实现
- MySQL之内联接、左联接、右联接、交叉联接
- 欢迎使用CSDN-markdown编辑器
- CString转换成其他类型——总结
- java第二次作业(6)
- BZOJ1725 Corn Fields牧场的安排 [状压DP]
- 实验二单链表的实现
- 01动态规划基础---最长递增子序列长度
- python 问题定期总结
- jsp与servlet的区别
- XTU 1268 鞍点
- hadoop自定义类型异常java.lang.RuntimeException: java.lang.NoSuchMethodException: twicesort.TwoKey.<init>()
- YUM实现LAMP
- bzoj 1568: [JSOI2008]Blue Mary开公司
- 一个日志查看工具的设想。