重名大师 2022-11-29 00:02 采纳率: 96.6%
浏览 15
已结题

这个代码一直超时,链表输入学生成绩并且逆序输出

想问一下这个代码要求是吧学生信息输入用链表在逆序输出
我放到网站上他就超时了不知道是哪里有问题(只学过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;}

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-11-29 04:10
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月9日
  • 已采纳回答 4月1日
  • 创建了问题 11月29日

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误