链表中的节点的数据域可以直接插入结构体吗?如下:
struct student
{
int num;
char name[10];
int grade;
};
struct stunode
{
struct student;
struct stunode * next;
};
如果这样可以的话,打印时要怎样写呢?(见最后几行,事实证明这样写是不可能成功的。。。)求指点
#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
char name[10];
int grade;
};
struct stunode
{
struct student;
struct stunode * next;
};
main()
{
int i;
struct stunode *p,*head;
struct student h[13]=
{
{2,"Lin",92},
{3,"Zhang",87},
{4,"Zhao",72},
{5,"Ma",91},
{9,"Zhen",85},
{11,"Wang",100},
{12,"Li",86},
{13,"Xu",83},
{16,"Mao",78},
{17,"Hao",95},
{20,"Lu",82},
{21,"Song",76},
{22,"Wu",88}
};
head=NULL;
for(i=0;i<13;i++)
{
p=(struct stunode *)malloc(sizeof(struct stunode));
p->next=head;
p->stu=h[i];
head=p;
}
for(i=1;i<=12;i++)
{
printf("%d %s %f\n",head->stu);
head++;
}
printf("%d %s %f\n",head->stu);
}
还有一个问题:数组节点是什么意思?