想问一下这个代码要求是吧学生信息输入用链表在逆序输出
我放到网站上他就超时了不知道是哪里有问题(只学过c语言的单向链表,不知道这个问题可不可以用这个知识点解决)
#include<stdio.h>
#include<malloc.h>
struct cell{
char xuehao[20];
char xingming[40];
char xingbie[2];
int nianlin;
int defen;
char dizhi[40];
struct cell*next;
struct cell*last;
};
struct cell*build(void)
{struct cell*head,*p,*tmp;
head=tmp=p=NULL;
int i=1;
p=(struct cell*)malloc(sizeof(struct cell));
scanf("%s",p->xuehao);
scanf("%s",p->xingming);
scanf("%s",p->xingbie);
scanf("%d",&(p->nianlin));
scanf("%d",&(p->defen));
scanf("%s",p->dizhi);
head=p;
p->next=NULL;
p->last=NULL;
while(i<=1)
{tmp=(struct cell*)malloc(sizeof(struct cell));
scanf("%s",tmp->xuehao);
if(tmp->xuehao[0]=='e'){p->next=NULL;break;}
scanf("%s",tmp->xingming);
scanf("%s",tmp->xingbie);
scanf("%d",&(tmp->nianlin));
scanf("%d",&(tmp->defen));
scanf("%s",tmp->dizhi);
tmp->last=p;
p->next=tmp;
p=p->next;
}
return head;
};
void uuu(struct cell*head)
{
struct cell*p;
int i=0;int j;int k;
p=head;
while(p->next!=NULL)
{
p=p->next;
}
while(p!=NULL)
{
printf("%s",p->xuehao);printf(" ");
printf("%s",p->xingming);printf(" ");
printf("%s",p->xingbie);printf(" ");
printf("%d",p->nianlin);printf(" ");
printf("%d",p->defen);printf(" ");
printf("%s",p->dizhi);
if(p->last!=NULL){printf("\n");}
p=p->last;
}
}
void release(struct cell*head)
{
struct cell*p0,*p;
p=head;
while(p!=NULL)
{
p0=p;
p=p->next;
free(p0);
}
}
int main(){
struct cell*head;
head=build();
if(head->next!=NULL){uuu(head);}
else printf("NULL");
release(head);
return 0;}