链表的建立

#include <stdio.h>

#include <stdlib.h>

#define null 0

typedef struct snode

{

char *name;

char *no;

int score[5];

}typedefdata;

typedef struct node

{

typedefdata data;

    struct node *next;

}linklist;
linklist *insert_new()

{

char flag;

int x;

char *na;

char *num;

int grade[5];

linklist *head,*rear,*p;

head = (struct node*)malloc(sizeof(linklist));//头节点的空间分配

rear = head;//头尾相连进行初始化

do{//do-while语句保证至少进行一次。

printf("name:");

scanf("%s",&na);

printf("No.:");

scanf("%s",&num);

printf("yuwen_grade:");

scanf("%d",&grade[0]);

printf("shuxue_grade:");

scanf("%d",&grade[1]);

printf("yingyu_grade:");

scanf("%d",&grade[2]);

printf("zhengzhi_grade:");

scanf("%d",&grade[3]);

printf("tiyu_grade:");

scanf("%d",&grade[4]);

p = (struct node*)malloc(sizeof(linklist));

p->data.name = na;

p->data.no = num;

for(x=0;x<5;x++)

p->data.score[x] = grade[x];

rear->next = p;

rear = p;

printf("\n\n continue?q for quit!");

getchar();

scanf("%c",&flag);

}while(flag != 'q');

rear->next = null;

return (head);

}
for(x=0;x<5;x++)

p->data.score[x] = grade[x];

 p->next = head->next;

 head->next = p;

printf("\n\n continue?q for quit!");
int main()

{

    insert_new();

return 0;

}

 

posted on 2016-04-07 20:01  自画何用费笔墨  阅读(121)  评论(0编辑  收藏  举报

导航