一个链表(问)题的修改,学生信息表
#include<stdio.h>#include<stdlib.h>
#include<string.h>
struct student
{
char num[20];
char name[20];
float score[5];
struct student*next;
};
struct student*head=NULL;
void insert(struct student*);
;
void insert ();
void print ();
void creat ();
void query ();
void main()
{
creat ();
print ();
query ();
}
void insert(struct student*newp)
{
struct student*p=head,*q=head;
if(head==NULL)
{
head=newp;
newp->next=NULL;
}
else
{
while(strcmp(p->num,newp->num)<0&&p->next!=NULL)
{
q=p;
p=p->next;
}
if(strcmp(p->num,newp->num)>0)
{
newp->next=p;
if(p==head)
head=newp;
else
q->next=newp;
}
else if(strcmp(p->num,newp->num)==0)
printf("input invalid!\n");
else
{
p->next=newp;
newp->next=NULL;
}
}
}
void creat ()
{
struct student*newp;
newp=(struct student*)malloc(sizeof(struct student));
printf("information(NO NAME SCORE):\n");
scanf("%s%s%f", &newp->num, &newp->name, &newp->score);
while(strcmp(newp->num,"#")!=0)
{
insert(newp);
newp=(struct student*)malloc(sizeof(struct student));
scanf("%s%s%f", &newp->num, &newp->name, &newp->score);
}
}
void print ()
{ int average=0;
struct student*p=head;
while(p!=NULL)
{
printf("s%s%f%\n",p->num,p->name,p->score);
p=p->next;
}
while(p!=NULL)
{
average=average+p->score;
p=p->next;
}
}
void query ()
{
struct student*p;
char sname[20],snum[20],value[20];
int find;
do
{
p=head;
find=0;
printf("please input del condition:\n");
printf("name search(sno,sname,sco):");
scanf("%s",sname);
printf("value");
scanf("%s",value);
if(strcmp(sname,"sno")==0)
while(p!=NULL)
{
if(strcmp(p->num,value)==0)
{
printf("%s%s%f\n",p->num,p->name,p->score);
find=1;
break;
}
p=p->next;
}
else if (strcmp(sname,"sco")==0)
{
while(p!=NULL)
{
if(strcmp(p->score,value)==0)
{
printf("%s%s%f\n",p->num,p->name,p->score);
find=1;
}
else
printf("not exist!\n");
if(!find)
printf("cannot find");
}
}
}
}
然后还有删除其中一个节点的操作不会编,求大神帮忙改一下