#include "stdio.h"
#include "stdlib.h"
#include "string.h"
void insert(void);
void del(); /*定义函数*/
void ser();
void output();
struct student
{
int num;
char name;
long tel;
long QQ;
struct student *next;
};
struct student *head,*p,*q,*newp;
main()
{
char a;
head=NULL;
while(a)
{
printf("please chiose one:\n");
printf("1 insert\n");
printf("2 del\n");
printf("3 serch\n"); /*主菜单*/
printf("4 output\n");
printf("5 exit\n");
scanf("%d",&a);
switch(a)
{
case 1: insert();break;
case 2: del();break; /*函数调用*/
case 3: ser();break;
case 4: output();break;
default :exit(0);
}
}
}
void insert() /*尾部插入方法*/
{
newp=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
head=newp;
else
{
p=head;
while(p)
p=p->next;
p=newp;
}
printf("please enter num:\n");
scanf("%d",&p->num);
printf("please enter name:\n");
scanf("%s",&p->name);
printf("please enter tel:");
scanf("%ld",&p->tel);
printf("please enter QQ:");
scanf("%ld",&p->QQ);
p->next=NULL;
free(newp);
return ;
}
void del(void) /*删除函数*/
{
long i;
printf("please enter num:\n");
scanf("%ld",&i);
p=head;
if(p->next==NULL)
p->next=NULL;
else
{
while(p->next->num==i)
{
q=(struct student *)malloc(sizeof(struct student));
q=p->next;
p->next=q->next;
}
}
free(q);
return ;
}
void ser(void) /*查找函数*/
{
int i;
printf("please enter num:\n");
scanf("%ld",&i);
if(head==NULL)
printf("the student is no.\n");
for(p=head;p;p=p->next)
{
if(p->num==i)
printf("%ld %s %ld %ld\n",p->num,p->name,p->tel,p->QQ);
else
printf("the student is no.\n");
}
return ;
}
void output() /*输出函数*/
{
p=head;
for(;p;p=p->next)
printf("%ld %s %ld %ld\n",p->num,p->name,p->tel,p->QQ);
return ;
}