回复 10楼 zjslwyp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
int no;
char name[20];
};
struct node
{
struct student stu;
struct node *pNext;
};
void printNode(struct node *pHead)
{
if(NULL == pHead)
return;
else
{
printNode(pHead->pNext);
printf("学号:%d\t,姓名:%s\n",pHead->stu.no,pHead->stu.name);
}
}
int main(void)
{
struct node *pHead = NULL;
struct node *pTemp = NULL;
struct node *p ;
pHead = (struct node *)malloc(sizeof(struct node));
pTemp = pHead;
pTemp->stu.no = 1;
strcpy(pTemp->stu.name,"张三");
p = (struct node *)malloc(sizeof(struct node));
p->stu.no = 2;
strcpy(p->stu.name,"李四");
p->pNext=NULL;
pTemp->pNext = p;
pTemp = pHead;
while(pTemp->pNext)
{
pTemp = pTemp->pNext;
}
p = (struct node *)malloc(sizeof(struct node));
p->stu.no = 3;
strcpy(p->stu.name,"王五");
p->pNext=NULL;
pTemp->pNext = p;
printNode(pHead);
return 0;
}
不建议使用递归,内存消耗太大了。。。。