C语言实验报告
实验目的:链表的基本操作添加,删除,排序
#include <>
#include <>
#include <>
struct StuNode
{
char ID[10];
char Name[10];
int Height;
StuNode *next;
};
typedef StuNode stulist;
void Addafter (stulist * list,char * id,char * name,int height)
{
if(!list||!id) return;
StuNode *p=new StuNode;
strcpy(p->ID,id);
strcpy(p->Name,name);
p->Height=height;
StuNode *q=list;
while(q->next)
{
q=q->next;
}
q->next=p;
p->next=NULL;
}
void ShowNode(stulist * list)
{
cout<<"现有数据是:"<<endl;
StuNode *p=list->next;
while(p)
{
cout<<p->ID<<" "<<p->Name<<" "<<p->Height<<endl;
p=p->next;
}
cout<<endl<<"*************************************"<<endl;
}
void Insert (stulist * list)
{
char Beid[10]="2014002";
char id[10]="1112223";
char name[10]="狗蛋";
int height=177;
if(!list||!id) return;
StuNode *p=new StuNode;
strcpy(p->ID,id);
strcpy(p->Name,name);
p->Height=height;
StuNode *q=list;
while(strcmp(q->ID,Beid)!=0)
{
q=q->next;
}
p->next=q->next;
q->next=p;
}
void Delete(stulist * list)
{
char id[10]="2014001";
StuNode *q=list;
StuNode *d=q->next;
while(strcmp(d->ID,id)!=0)
{
q=q->next;
d=d->next;
}
q->next=d->next;
delete d;
}
void main()
{
stulist list_1;
=NULL;
char name[10],id[10];
int height;
A
链表实验报告 来自淘豆网m.daumloan.com转载请标明出处.