#include using namespace std;
struct Student
{
int id;
char *name;
float score;
Student *next;
};
Student* Create();
Student* Create(int i, char *ch, float sc);
void Insert(Student *h, Student *p);
void Output(Student *h);
Student* Search(Student *h, const int id);
void Delete(Student *h, Student *p);
int main(int argc, char* argv[])
{
Student *head, *p;
head=Create();
p=Create(1,"a",83);
Insert(head,p);
p=Create(2,"b",97);
Insert(head,p);
p=Create(3,"c",64);
Insert(head,p);
p=Create(4,"d",76);
Insert(head,p);
p=Create(5,"e",83);
Insert(head,p);
Output(head);
p=Search(head,2);
Delete(head,p);
Output(head);
return 0;
}
Student* Create()
{
Student *head;
head=(Student *)malloc(sizeof(Student));
head->next=NULL;
return head;
}
Student* Create(int i, char *ch, float sc)
{
Student *p;
p=(Student *)malloc(sizeof(Student));
p->id=i;
p->name=ch;
p->score=sc;
p->next=NULL;
return p;
}
void Insert(Student *h,Student *p)
{
/*
Student *cur;
cur=h;
while(cur->next!=NULL)
{
cur=cur->next;
}
cur->next=p;
*/
if(h->next==NULL)
{
h->next=p;
}
else
{
Student *cur,*q;
for(q=h->next;q!=NULL;q=q->next)
{
if(q->id>p->id)
break;
}
for(cur=h; cur->next!=q; cur=cur->next);
if(q==NULL)
{
cur->next=p;
}
else
{
p->next=q;
cur->next=p;
}
}
}
void Output(Student *h)
{
if(h->next==NULL)
{
cout
while(cur!=NULL)
{
cout
}
}
}
Student* Search(Student *h,const int id)
{
if(h->next==NULL)
{
cout
while(cur!=NULL)
{
if(id==cur->id)
break;
cur=cur->next;
}
if(cur==NULL)
{
cout
{
cout
while(cur->next!=p)
{
cur=cur->next;
}
cur->next=p->next;
p=NULL;
free(p);
}
}