#include<stdio.h>
#include<stdlib.h>
struct Student
{
char cName[20];
int iNumber;
struct Student *pNext;
};
//节点由数据部分和指针部分两部分构成
int iCount;//链表长度
struct Student *Create()
{
struct Student *pHead = NULL;
struct Student *pEnd, *pNew;
iCount = 0;
pEnd = pNew = (struct Student *)malloc(sizeof(struct Student));//结构体Student分配一个特定大小的动态内存
scanf_s("%s",&pNew->cName);
scanf_s("%d",&pNew->iNumber);
while (pNew->iNumber != 0)
{
iCount++;
if (iCount == 1)//此时链表有一个节点
{
pNew->pNext = NULL;
pNew = pEnd;
pHead = pNew;
}
else
{
pNew->pNext = NULL;
pEnd->pNext = pNew;
pEnd = pNew;
}
pNew = (struct Student *)malloc(sizeof(struct Student));
scanf_s("%s", &pNew->cName);
scanf_s("%d", &pNew->iNumber);
}
free(pNew);
return pHead;
};
#include<stdio.h>
struct Print(struct Student* pHead)//将链表的头指针放入Print函数中
{
struct Student* pTemp;
int ilndex = 1;
printf("---这个链表中有%d个成员---\n", ilndex);
pTemp = pHead;
while (!pTemp = NULL)
{
printf("成员号是 %d", ilndex);
printf("成员姓名是 %d", pTemp->cName);
printf("学号是 %d\n", pTemp->iNumber);
pTemp = pTemp->pNext;
ilndex++;
}
}