数据结构之链表的实例
来源:互联网 发布:西门子冰箱知乎 编辑:程序博客网 时间:2024/06/05 09:25
/*学生管理系统*/#include<iostream>#include<string.h>using namespace std;class Stu{public: char no[20]; string name; double score; Stu &operator=(Stu &student);};Stu &Stu::operator=(Stu &student){ strcpy(this->no,student.no); this->name=student.name; this->score=student.score; return *this;}class ListNode{public: Stu data; ListNode *next;};class List{public: List();//创建 ~List();//销毁 bool ListInsertTail(ListNode *pNode);//尾插法 void ListTraverse();//遍历 ListNode *pList;};List::List(){ pList=new ListNode; pList->next=NULL;}List::~List(){ ListNode *currentNode=pList; while(currentNode->next!=NULL) { ListNode *temp=currentNode->next; delete currentNode; currentNode=temp; } delete pList; pList=NULL;}bool List::ListInsertTail(ListNode *pNode){ ListNode *currentNode=pList; while(currentNode->next!=NULL) { currentNode=currentNode->next; } ListNode*newNode=new ListNode; if(newNode==NULL) return false; newNode->data=pNode->data; newNode->next=NULL; currentNode->next=newNode; return true;}void List::ListTraverse(){ ListNode *currentNode=pList; while(currentNode->next!=NULL) { currentNode=currentNode->next; cout<<endl<<currentNode->data.name<<"\t"; cout<<currentNode->data.no<<"\t"; cout<<currentNode->data.score<<endl; }}void create(List *p){ cout<<"几个学生?\n"; int n; cin>>n; for(int i=0;i<n;i++) { ListNode q; cout<<"请输入学生学号和学生姓名和学生成绩"; cin>>q.data.no>>q.data.name>>q.data.score; p->ListInsertTail(&q); }}void add(List *p){ cout<<"插入几个学生?\n"; int n; cin>>n; for(int i=0;i<n;i++) { ListNode q; cout<<"请输入学生学号和学生姓名和学生成绩"; cin>>q.data.no>>q.data.name>>q.data.score; p->ListInsertTail(&q); }}void Delete(List *p){ bool flag=false; cout<<"请问选择删除的姓名"; string temp; cin>>temp; ListNode *currentNode=p->pList; ListNode *currentNodebefore=currentNode; while(currentNode->next!=NULL) { currentNode=currentNode->next; if(currentNode->data.name==temp) { currentNodebefore->next=currentNode->next; flag=true; break; } } if(flag) { cout<<"已经删除完毕"<<endl; } else { cout<<"找不到删除对象"<<endl; }}void Find(List *p){ cout<<"你要查找的姓名是"; string temp; cin>>temp; ListNode *currentNode=p->pList; while(currentNode->next!=NULL) { currentNode=currentNode->next; if(currentNode->data.name==temp) { cout<<endl<<currentNode->data.name<<"\t"; cout<<currentNode->data.no<<"\t"; cout<<currentNode->data.score<<endl; } }}void Revise(List *p){ cout<<"请问要修改的名字"; string temp; cin>>temp; cout<<"请问要修改的成绩是多少"; double sum; cin>>sum; ListNode *currentNode=p->pList; while(currentNode->next!=NULL) { currentNode=currentNode->next; if(currentNode->data.name==temp) { currentNode->data.score=sum; break; } }}void menu(){ bool flag=true; int n; List *p=new List(); while(flag) { cout<<"******学生成绩管理系统******\n"; cout<<"****0:建立******************\n"; cout<<"****1:添加******************\n"; cout<<"****2:删除******************\n"; cout<<"****3:查询******************\n"; cout<<"****4:显示******************\n"; cout<<"****5:修改******************\n"; cout<<"****6:退出******************\n"; cin>>n; switch(n) { case 0:create(p);break; case 1:add(p);break; case 2:Delete(p);break; case 3:Find(p);break; case 4:p->ListTraverse();break; case 5:Revise(p);break; case 6:flag=false;break; } } delete p; p=NULL;}int main(void){ menu();}
阅读全文
0 0
- 数据结构之链表的实例
- 数据结构之链表的实例
- 数据结构之队列实例
- 【数据结构】单向链表实例
- 数据结构3-链表生成的实例与分析
- C语言数据结构之图的邻接矩阵的应用实例
- 数据结构之栈的简单实例c++实现
- 数据结构10-排序方法之直接插入排序的实例
- 数据结构11-排序方法之选择排序的实例
- 数据结构12-排序方法之冒泡排序的实例
- 数据结构13-排序方法之希尔排序的实例
- 数据结构14-排序方法之快速排序的实例
- 数据结构之队列应用实例
- 数据结构之线性链表的算法
- 数据结构之双向链表的实现
- 数据结构之链表的删除
- 数据结构之链表的插入
- 数据结构之链表的Java实现
- CentOS 安装 supervisor 以及设置 Laravel 队列设置
- 工程应用标准示范程序:将一个ADC采样值转换为ASCII码
- 最简洁高效的Git 命令上传代码【以及Git的一些经常使用的小命令】
- Linux下socket编程之线程池的实现
- jQuery的extend的用法
- 数据结构之链表的实例
- Luncene学习笔记 -- day04 分词器
- C++11auto类型说明符
- Java连接hive报错01
- C语言——完数
- Springmvc的入门---配置
- python数据持久化到文件并读取:pickle的使用
- struts报错严重: Dispatcher initialization failed Unable to load configuration.
- 文本特征选择-互信息