双链表--学生成绩表
来源:互联网 发布:6city类似软件 编辑:程序博客网 时间:2024/05/22 03:17
#include<iostream> using namespace std; struct Node { int data; Node *prior;Node *next; }; class DoubleList { private: Node *first; public: DoubleList(); DoubleList(int a[],int n); ~DoubleList(); void Insert(int i,int x); int Delete(int i); void PrintList(); }; DoubleList::DoubleList() { first=new Node; first->next=NULL; } DoubleList::DoubleList(int a[],int n) { Node *r,*s; first=new Node; r=first; for(int i=0;i<n;i++) { s=new Node; s->data=a[i]; s->next=NULL; r->next=s; s->prior=r; r=s; } r->next=NULL; } DoubleList::~DoubleList() { Node *q=NULL; while(first!=NULL) { q=first; first=first->next; delete q; } } void DoubleList::Insert(int i,int x) { Node *p=first,*s=NULL; int count=0; while(p!=NULL&&count<i-1) {p=p->next; count++;} if(p==NULL)throw"位置"; else{ s=new Node;s->data=x; s->prior=p; s->next=p->next; p->next->prior=s; p->next=s; } } int DoubleList::Delete(int i) { Node *p=first; int count=0; while(p!=NULL&&count<i) { p=p->next; count++; } if(p==NULL) throw"位置"; else{ (p->prior)->next=p->next; (p->next)->prior=p->prior; free(p); } return 0; } void DoubleList::PrintList() { Node *p=first->next; while(p!=NULL) { cout<<p->data<<" "; p=p->next; } cout<<endl; } int main() { int stu_score[5]={88,92,52,68,78}; DoubleList L(stu_score,5); cout<<"成绩表数据为:"<<endl; L.PrintList(); cout<<"在第三个位置插入成绩"<<endl; try { L.Insert(3,78); } catch(char *s) { cout<<s<<endl; } cout<<"插入后数成绩表为:"<<endl; L.PrintList(); cout<<"删除前成绩表为:"<<endl; L.PrintList(); cout<<"删除第一个成绩"<<endl; try { L.Delete(1); } catch(char *s) { cout<<s<<endl; } cout<<"删除后成绩表为:"<<endl; L.PrintList(); return 0; }
阅读全文
0 0
- 双链表--学生成绩表
- 学生成绩表 (二)
- 学生成绩表sql示例
- 学生成绩表常用sql
- 第一期题目*学生成绩表*
- 使用java导出学生成绩表
- 学生成绩表的常用查询
- 学生课成表成绩表相关题目50题
- 学生课成表成绩表相关题目50题
- 创建学生表、课程表、成绩表sql语句
- 关于学生成绩表的两个SQL题目
- 学生信息表 成绩表+12章练习
- 学生表/课程表/教师表/成绩表-多表查
- 顺序表———学生成绩表
- 成绩表
- MySql 学生表 科目表 成绩表 查询学生各科成绩
- 多表数据(学生表、初中成绩表及高中成绩表)输出XML格式
- 学生成绩表中排名字段的sql语句
- yum在cnetos下安装mysql
- 软件安装
- 第五周 项目1-建立顺序栈算法库
- Java开发代码规范之编程规约(一)——命名风格
- 人工智能
- 双链表--学生成绩表
- 计算机网络
- usaco
- 【zzuli2132】Tmk吃汤饭
- 什么是事务
- 回归分类学习
- ColorMatrix颜色矩阵让图片千变万化
- ros定制自己的消息类型
- BZOJ 2064: 分裂 状压DP