c语言使用链表编写一个可以实现班级学生管理系统,增加,删除,修改学生信息
#include <stdio.h>#include <stdlib.h>
#include <string.h>
typedef struct tagPerson
{
char name[20];
char 易做图[20];
long tel[20];
struct tagPerson *next;
}Person;
Person * create(int n)
{
Person *head=NULL,*pre= NULL;
for(int i=0;i<n;i++ )
{
Person *temp=malloc(sizeof(Person));
printf("输入姓名:");
scanf("%s",temp->name);
printf("输入性别:");
scanf("%s",temp->易做图);
printf("输入电话:");
scanf("%ld",temp->tel);
if (head==NULL)
{
head=temp;
}
if (pre!=NULL)
{
pre->next=temp;
}
pre=temp;
}
pre->next=NULL;
return head;
}
void show(Person * head)
{
Person *p=head;
while (p)
{
printf("\n%s\t%s\t%ld\n",p->name,p->易做图,p->tel);
p=p->next;
}
}
void destroy(Person *head)
{
Person *a=head,*b;
while (a)
{
b=a->next;
free(a);
a=b;
}
}
Person *delete(Person *head ,long *tel)
{
Person *p=head;
Person *before=NULL,*me=NULL,*t=NULL;
while (p)
{
if (strcmp(p->tel, tel)==0)
{
before=t;
me=p;
break;
}t=p;
p=p->next;
}
if (p)
{
if (before==NULL&&me!=NULL)
{
head=me->next;
free(me);
}
else if(before!=NULL&&me->next!=NULL)
{
before->next=me->next;
free(me);
}
else if(before!=NULL&&me->next==NULL)
{
before->next=NULL;
free(me);
}
}return head;
}
int main(int argc, const char * argv[])
{
int n;
printf("请输入人数");
scanf("%d",&n);
Person *head=create(n);
show(head);
printf("修改后的数据:");
printf("删除后的数据:");
delete(head, "1234");
show(head);
destroy(head);
return 0;
}
补充:软件开发 , C语言 ,