新人求指教单链表~~~代码如下
#include<stdio.h>#include<stdlib.h>
typedef struct _student
{
int No;
char name[10];
int age;
char sex;
int order;
}student;
typedef struct _Node
{
student data;
struct _Node *next;
}List;
List *Create_list()
{
int data;
student data1, data3, data5;
student data2, data4;
List *head = NULL, *pcur = NULL, *plist = NULL;
head = (List *)malloc(sizeof(List));
//head->data = 0;
head->next = NULL;
printf("\nPlease enter the data of node(-1:quit) ");
scanf("%d",&(data1.No));
scanf("%s", &(data2.name));
scanf("%d", &(data3.age));
scanf("%c", &(data4.sex));
scanf("%d", &(data5.order));
pcur = head;
while (data != -1)
{
plist = (List *)malloc(sizeof(List));
plist->data.No = data1.No;
plist->data.age = data2.name;
plist->data.name = data3.age;
plist->data.sex = data4.sex;
plist->data.order = data5.order;
plist->next = NULL;
pcur->next = plist;
pcur = plist;
printf("\nPlease enter the data of node(-1:quit) ");
scanf("%d", &data);
}
return head;
}
int print(List *head)
{
List *p = NULL;
if (head == NULL)
{
return -1;
}
p = head->next;
printf("begin");
while (p)
{
printf("%d %s %d %c %d", p->data.No, p->data.name, p->data.age, p->data.sex, p->data.order);
p = p->next;
}
}
int main()
{
List *head = NULL;
head = Create_list();
print(head);
system("pause");
return;
}
总是运行不了 求指教