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

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{
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;
GIS2010.ListDelete(delID);
break;
case 0:
break;
}
};
return 0;
}
current=current->next;
}
}wk.baidu.com
};
int main(int argc, char* argv[])
{
printf("Hello World!\n");
SeqList GIS2010;
int x=1;
while(x!=0){
printf("请输入以下选项:\n");
printf("1:信息浏览\n");
cout<<"NAME="<<endl;
cin>>newStudent.name;
cout<<"SEX="<<endl;
cin>>newStudent.sex;
cout<<"GRADE="<<endl;
cin>>newStudent.grade;
cout<<"TEL="<<endl;
cin>>newStudent.tel;
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;
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;
}
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;
cout<<"AGE="<<endl;
cin>>newStudent.age;
newStudent.next=NULL;
GIS2010.ListInsert(newStudent);
break;
case 3:
char delID[10];
cout<<"请输入想要删除数据项的ID号码"<<endl;
cin>>delID;
利用单链表实现学生信息管理
// Exe3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <string.h>
struct Student
相关文档
最新文档