• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天之道

            享受編程的樂(lè)趣。
            posts - 118, comments - 7, trackbacks - 0, articles - 0
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            創(chuàng)建動(dòng)態(tài)鏈表

            Posted on 2012-05-12 10:29 hoshelly 閱讀(1820) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): DS && Algorithm

            建立一個(gè)鏈表,其中的節(jié)點(diǎn)包括學(xué)號(hào),成績(jī)信息。要求用動(dòng)態(tài)插入鏈表的方法實(shí)現(xiàn),就是輸入第一個(gè)節(jié)點(diǎn)信息時(shí),則必須創(chuàng)建該鏈表,之后每輸入一個(gè)學(xué)生節(jié)點(diǎn)的基本信息,就把該節(jié)點(diǎn)插入到已有的鏈表當(dāng)中。要求按照學(xué)號(hào)順序插入。輸入的時(shí)候可以不按照學(xué)號(hào)的順序,輸入0 0 表
            示輸入結(jié)束。
            (不允許對(duì)輸入的數(shù)據(jù)排序后再創(chuàng)建鏈表)

            Sample Input

            1 50
            4 60
            2 70
            3 80
            5 64
            0 0 

            Sample Output

            The list is:
            1 50
            2 70
            3 80
            4 60
            5 64



            #include<stdio.h>
            #include<stdlib.h>

            struct student
            {
                int number;
                float score;
                struct student *next;
            };

            int main()
            {
                int n=0;
                struct student *head,*p1;
                p1=(struct student*)malloc(sizeof(struct student));
                scanf("%d %f",&p1->number,&p1->score);
                head=p1;
                head->next=NULL;
                while(p1->number!=0 && p1->score!=0)
                {
                      n++;
                      p1->next=(struct student*)malloc(sizeof(struct student));
                      p1=p1->next;
                      p1->next=NULL;
                      scanf("%d %f",&p1->number,&p1->score);
                }
                
                struct student *p3,*p4;
                p3=(struct student*)malloc(sizeof(struct student));
                p4=(struct student*)malloc(sizeof(struct student));
                for(int i=0;i<n;i++) 
                {    
                    p3=head;
                    for(int j=0;j<n-i-1;j++)
                    {
                        p4=p3->next;
                        if(p3->number>p4->number)
                        {
                            int k=p3->number;
                            p3->number=p4->number;
                            p4->number=k;
                            float m=p3->score;
                            p3->score=p4->score;
                            p4->score=m;
                        }
                        p3=p3->next;
                    }
                }
                printf("The list is:\n");
                 p3=head;
                 do
                 {
                  if(p3->number ==0 && p3->score==0)
                      continue;
                  printf("%d %.0f\n",p3->number,p3->score); 
                  p3=p3->next;
                }while(p3!=NULL);

                free(p1);
                free(p3);
                free(p4);
                return 0;
            }
                
            精品综合久久久久久88小说| 欧美久久精品一级c片片| 欧美激情精品久久久久久久| 亚洲国产精品无码久久九九| 99久久精品免费看国产一区二区三区| 久久亚洲sm情趣捆绑调教| 久久久久国产精品嫩草影院| 久久水蜜桃亚洲av无码精品麻豆| 人人狠狠综合久久亚洲88| 日韩影院久久| 狠狠色丁香婷婷久久综合不卡 | 亚洲国产精品热久久| 久久久久久久久久久免费精品| 久久久久亚洲精品日久生情| 99久久久精品| 久久狠狠爱亚洲综合影院 | 日本福利片国产午夜久久| 久久无码一区二区三区少妇| 久久人人爽人人爽人人AV| 欧美精品丝袜久久久中文字幕 | 亚洲精品乱码久久久久久蜜桃图片 | 亚洲伊人久久成综合人影院| 日产精品久久久久久久| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久婷婷国产剧情内射白浆| 国产成人精品久久综合| 久久国产乱子精品免费女| 亚洲国产另类久久久精品小说| 武侠古典久久婷婷狼人伊人| 日本精品久久久久中文字幕| 精品久久人妻av中文字幕| 久久久久久国产精品美女| 区久久AAA片69亚洲| 亚洲欧美精品一区久久中文字幕| 精品久久久无码中文字幕天天| 精品免费久久久久久久| av无码久久久久久不卡网站| 久久天堂AV综合合色蜜桃网| 国产精品美女久久久m| 精品人妻久久久久久888| 精品国产福利久久久|