建立一个有n个结点的单链表,要求从尾部进行插入
菜鸟先飞 谁能用C语言编写以上问题?摆脱了
#include "stdio.h"
#include "stdlib.h"
#define N 3
struct student {
int c;
struct student *next;
};
struct student* gethead() {
int i;
struct student *head,*p,*q;
head=malloc(sizeof(struct student));
head->next=NULL;
p=malloc(sizeof(struct student));
scanf("%d",&p->c);
head->next=p;
q=p;
p->next=NULL;
for(i=0;i<N-1;i++) {
p=malloc(sizeof(struct student));
scanf("%d",&p->c);
q->next=p;
p->next=NULL;
q=p;
}
return head;
}
看这个可以不