c语言 增加 删除 修改的功能 不用链表,C语言单链表的建立,查找,添加,删除,修改功能实现...

这个程序是我在初学单链表的时候编写出来的代码,所以还不完整,希望对各位在理解单链表的时候起到一点儿的帮助,而且欢迎各位同学讨论技术,以技术广交天下好友。本人QQ号:648422746

#include

#include

#include

#include

#define len (struct staff *)malloc(sizeof(struct staff))

struct staff

{

char name[10];

int salary;

struct staff *next;

};

struct staff *creat();

void print(struct staff *);

struct staff *find(struct staff *);

struct staff *addmessage(struct staff *);

struct staff *deletemessage(struct staff *);

struct staff *changemessage(struct staff *);

main()

{

struct staff *head,*p;

head=creat();

print(head);

p=find(head);

head=addmessage(head);

head=deletemessage(head);

head=changemessage(head);

}

struct staff *creat()

{

struct staff *head,*p1,*p2;

int n;

n=0;

head=NULL;

p1=len;

printf("/n请键入学生的信息 (包括名字,分数):/n");

scanf("%s%d",p1->name,&p1->salary);

while(p1->salary>0)

{

n++;

if(n==1)

head=p1;

else

p2->next=p1;

p2=p1;

p1=len;

scanf("/n%s%d",p1->name,&p1->salary);

}

p2->next=NULL;

return head;

}

void print(struct staff *head)

{

struct staff *p;

p=head;

while(p!=NULL)

{

printf("/n%s%d",p->name,p->salary);

p=p->next;

}

}

struct staff *find(struct staff *head)

{

struct staff *p1;

char findname[10];

p1=head;

printf("/nplease input you find name:/n");

scanf("%s",findname);

while(p1!=NULL)

{

if(strcmp(findname,p1->name)==0)

{

printf("/n%s%d",p1->name,p1->salary);

return p1;

}

else

p1=p1->next;

}

if(p1=NULL)

printf("/n没有你要查找的学生的信息/n");

}

struct staff *addmessage(struct staff *head)

{

struct staff *p1,*p2;

p1=head;

p2=head;

p1=len;

printf("/n请输入你要添加的信息:/n");

scanf("/n%s%d",p1->name,&p1->salary);

if(head!=NULL)

{

p2=head;

p1->next=p2;

head=p1;

}

else

head=p1;

print(head);

return head;

}

struct staff *deletemessage(struct staff *head)

{

struct staff *p1,*p2;

char deletename[10];

p1=head;

p2=head;

printf("/n删除学生的信息,请键入该学生的姓名:/n");

scanf("%s",deletename);

while(strcmp(deletename,p1->name)!=0)

{

p2=p1;

p1=p1->next;

}

if(strcmp(head->name,p1->name)==0)

{

head=p1->next;

}

else if(strcmp(deletename,p1->name)==0)

{

p2->next=p1->next;

}

free(p1);

print(head);

return head;

}

struct staff *changemessage(struct staff *head)

{

struct staff *p;

char changename[10];

p=head;

printf("/n修改学生的信息,请键入该学生的名字:");

scanf("%s",changename);

while(strcmp(changename,p->name)!=0)

{

p=p->next;

}

printf("/n该学生的信息为:%s%d",p->name,p->salary);

printf("/n请重新键入该学生的信息包括名字,分数:");

scanf("%s%d",p->name,&p->salary);

printf("/n全部学生的信息如下:/n");

print(head);

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值