C語言鏈表__C語言

來源:互聯網
上載者:User

title:輸入若干個學生的資訊(包括學號、姓名和成績),輸入學號為0時輸入結束。建立一個單向鏈表,再輸入一個成績值,將成績大於等於該值的學生資訊輸出。

input:3n+2行,每3行為一個學生的資訊,分別為學號,姓名和成績。倒數第二行為0,表示輸入結束。最後一行為一個整數,代表分數。

output:若干行,每三行代表一個學生的資訊。


#include<stdio.h>

#include<string.h>

#include<stdlib.h>

 

struct stud_node{                

    int long num;

    char  name[20];

    int    score;

   struct stud_node *next;

};

 

int main()

{  int size,score;char name[20];int long num;

   struct stud_node *head,  *tail,*p,*ptr;

   head = tail = NULL;

   size = sizeof(struct stud_node);

 

   scanf("%ld", &num);

   while(num!=0)

         {

             scanf("%s%d", name, &score);

       p=(struct stud_node *) malloc(size);

 

       p->num =num;

        strcpy(p->name, name);

       p->score = score;

       p->next = NULL;

       if(head == NULL)

           head = p;

       else

           tail->next = p;

       tail=p;

       scanf("%ld", &num);

         }

         ints;

         scanf("%d",&s);

 

         //printf("%d",s);

         for(ptr=head;ptr!=NULL;ptr=ptr->next)

    if(ptr->score >= s)

       printf("%ld\n%s\n%d\n",ptr->num,ptr->name,ptr->score);

 

return 0; }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.