收藏 分销(赏)

利用单链表实现学生信息管理.doc

上传人:仙人****88 文档编号:9399464 上传时间:2025-03-24 格式:DOC 页数:3 大小:17.54KB
下载 相关 举报
利用单链表实现学生信息管理.doc_第1页
第1页 / 共3页
利用单链表实现学生信息管理.doc_第2页
第2页 / 共3页
点击查看更多>>
资源描述
利用单链表实现学生信息管理 // Exe3.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream.h> #include <string.h> struct Student { char id[10]; char name[10]; char sex[10]; char grade[10]; char tel[20]; int age; Student *next; }; class SeqList {public : Student *head; Student *current,*previous; int length; SeqList(){ head= new Student; head->next=NULL; length=0; } bool IsListEmpty(){ return length==0; } void ListDelete(char ID[]){ previous=head; current=head->next; for(int i=0;i<length&&current!=NULL;i++){ //如果当前数据的id等于用户输入要删除数据的id,进行删除操作。 if(strcmp(current->id,ID)==0){ previous->next=current->next; length=length-1; return; } previous=current; current=current->next; } cout<<"ID="<<ID<<"的学生没有找到,可能是不存在!"; } void ListInsert(Student x){ Student *tmp=new Student; *tmp=x; tmp->next=head->next; head->next=tmp; length++; } void ShowAll(){ current=head->next; for(int i=0;i<length;i++){ cout<<"ID="<<current->id<<"\tNAME="<<current->name<<"\tSEX="<<current->sex<<"\tGRADE="<<current->grade<<"\tTEL="<<current->tel<<"\tAGE="<<current->age<<endl; current=current->next; } } }; int main(int argc, char* argv[]) { printf("Hello World!\n"); SeqList GIS2010; int x=1; while(x!=0){ printf("请输入以下选项:\n"); printf("1:信息浏览\n"); printf("2:插入信息\n"); printf("3:删除信息\n"); printf("0:退出程序\n"); cin>>x; switch(x){ case 1: GIS2010.ShowAll(); break; case 2: Student newStudent; cout<<"ID="<<endl; cin>>newStudent.id; cout<<"NAME="<<endl; cin>>newStudent.name; cout<<"SEX="<<endl; cin>>newStudent.sex; cout<<"GRADE="<<endl; cin>>newStudent.grade; cout<<"TEL="<<endl; cin>>newStudent.tel; cout<<"AGE="<<endl; cin>>newStudent.age; newStudent.next=NULL; GIS2010.ListInsert(newStudent); break; case 3: char delID[10]; cout<<"请输入想要删除数据项的ID号码"<<endl; cin>>delID; GIS2010.ListDelete(delID); break; case 0: break; } }; return 0; }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服