c语言中链表学生成绩从大到小,C语言链表实现学生成绩信息的管理

#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);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值