麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

C語言實現動態鏈表的創建、刪除、插入、輸出(CentOS6.5上調試成功)

2019-11-14 09:15:05
字體:
來源:轉載
供稿:網友

該代碼是基于網上其他代碼修改而來,原來的代碼有錯誤,以下是我修改后并在CentOS上調試成功的代碼:

#include  <stdio.h>#include <stdlib.h>#include <unistd.h>#define LEN sizeof(struct student)struct student{    int num;    char name[10];    float score;    struct student *next;};static unsigned inode = 1;void fill(char c[], int n, char ch);//填充數組void del(struct student *ph, int n);//刪除指定序號的節點void insert(struct student *ph, int n);//在指定序號后插入節點void output(struct student *ph);//輸出所有節點struct student *input(void);//輸入新節點void clearline(int n);//分割線int main(){        struct student *head,*ps,*pa,*pb;    int u;    char flag = 'y';    head = ps = pa = (struct student *)malloc(LEN);    fill(pa->name,10,'/0');    //輸入數據,建立鏈表    while(flag != 'n'){                PRintf("please input student informations: /n");        printf("Num/tName/tScore/n");        scanf("%d %s %f", &pa->num, pa->name, &pa->score);        flag = getchar();        printf("Press any key input data continue, otherwise press n quit:");        flag = getchar();        if(flag != 'n'){            clearline(60);            pa->next = (struct student *)malloc(LEN);            pa = pa->next;            fill(pa->name,10,'/0');            inode++;        }    }            pa->next = NULL;    output(ps);          //刪除節點    printf("which student's num do you want to del?/n");    printf("please input the num that you want to del:");    scanf("%d", &u);    if(u > inode){        printf("input error!/n");        exit(1);    }    if(u == 1){        pb = head;        ps = head->next;        free(pb);        head = pb = pa = ps;    }else        del(ps,u);    output(ps);    //插入節點    printf("which student's num do you want to insert after:");    scanf("%d",&u);    if(u>inode){        printf("input error!/n");        exit(1);    }    if(u == 0){        pb = head;        head = ps = pa = input();        pa->next = pb;        inode++;    }else{        insert(ps, u);    }    output(ps);    return 0;}void fill(char c[], int n, char ch){    int i;    for(i=0;i<=n;i++){        *(c+i) = ch;    }}void del(struct student *ph, int n){    int i;    struct student *pb,*pf;    pb = pf = ph;    for(i=1;i<=n-2;i++){        ph = ph->next;    }    if(n == inode){        pb = ph->next;        ph->next = NULL;        free(pb);    }else{        pb = ph->next;        ph->next = (ph->next)->next;        free(pb);    }    inode--;}void insert(struct student *ph, int n){    int i;    struct student *pa,*pb,*p_new,*ps;    ps = pa = ph;    p_new = (struct student *)malloc(LEN);    fill(p_new->name,10,'/0');    printf("please input the new student informations:/n");    printf("Num/tName/tScore:/n");    scanf("%d %s %f",&p_new->num,p_new->name,&p_new->score);    for(i=1;i<n;i++){        pa = pa->next;    }    pb = pa->next;    pa->next = p_new;    p_new->next = pb;    inode++;    }void output(struct student *ph){    int i;    struct student *pa;    printf("/n*****students list*****/n");    printf("Order/tNum/tName/tScore/n");        pa = ph;    for(i=1;pa!=NULL;i++){        printf("%d/t%d/t%s/t%.2f/n", i,pa->num,pa->name,pa->score);        pa=pa->next;    }    printf("totol %d /n",inode);   }struct student *input(void){    struct student *pa;    pa = (struct student *)malloc(LEN);    printf("please the new student information/n");    printf("Num/tName/tScore/n");    scanf("%d %s %f", &pa->num, pa->name, &pa->score);    return pa;}void clearline(int n){    int space;    printf("/r");    for(space=0;space<n;space++){        printf("-");    }    printf("/r");}

運行過程及結果:

please input student informations: Num     Name    Score1       aa      10Press any key input data continue, otherwise press n quit:yplease input student informations: -------------------------Num     Name    Score2       bb      20Press any key input data continue, otherwise press n quit:yplease input student informations: -------------------------Num     Name    Score3       cc      30Press any key input data continue, otherwise press n quit:n*****students list*****Order   Num     Name    Score1       1       aa      10.002       2       bb      20.003       3       cc      30.00totol 3 which student's num do you want to del?please input the num that you want to del:2*****students list*****Order   Num     Name    Score1       1       aa      10.002       3       cc      30.00totol 2 which student's num do you want to insert after:1please input the new student informations:Num     Name    Score:2       bb      20*****students list*****Order   Num     Name    Score1       1       aa      10.002       2       bb      20.003       3       cc      30.00totol 3 

結束


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天天操天天碰 | 亚洲网在线观看 | 久久精品电影网 | 好吊色欧美一区二区三区四区 | 一级大黄毛片免费观看 | 日韩黄色精品视频 | 黄色的视频在线观看 | hd日本xxxx| 毛片在线免费观看完整版 | 国产精品久久久久久久av | 成人福利在线播放 | 欧美福利视频一区二区 | 国产成人综合在线视频 | 亚洲天堂午夜 | 久草干 | 精品一区二区三区中文字幕老牛 | 国产88久久久国产精品免费二区 | 国产精品一区二区三区在线看 | av成人一区二区 | 九九热视频免费观看 | 永久免费黄色大片 | 日韩视频一区二区三区四区 | 九九热免费视频在线观看 | 香蕉成人在线视频 | 福利一区二区三区视频在线观看 | 婷婷久久综合九色综合色多多蜜臀 | 中国老女人一级毛片视频 | 欧美一级毛片欧美一级成人毛片 | 日韩欧美精品中文字幕 | 亚洲婷婷日日综合婷婷噜噜噜 | 黄色大片网站在线观看 | 国产成人精品一区二区三区电影 | 欧美视频一二区 | 毛片在线免费观看完整版 | 国产人成精品综合欧美成人 | 久久人人97超碰国产公开结果 | 国产一级桃视频播放 | 日日草天天干 | 久草在线视频网 | 亚洲精品永久视频 | 久久精品中文字幕一区二区三区 |