链表(C语言编写)

基于C语言编写的链表,可以直接复制,可以运行

#include<stdio.h>
#include<stdlib.h>
typedef  struct Student
{
	int num;
	char name[10];
	struct Student *pnext;
}STU;
STU*GreatList()
{
	STU*p = (STU*)malloc(sizeof(STU));
	p->pnext = NULL;
	return p;
}
void AddNode(STU*p)
{
	STU*pNew = NULL;
	int n;
	printf("renshu");
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		pNew = (STU*)malloc(sizeof(STU));
		printf("11");
		printf("  ");
		scanf("%s", pNew->name);
		printf("222");
		scanf("%d", &pNew->num);
		pNew->pnext = NULL;
		p->pnext = pNew;
		p = p->pnext;
	}
}
int main()
{
	STU *pStu = NULL;
	pStu = GreatList();
	AddNode(pStu);
	printf("%d\t%s\n", pStu->pnext->num, pStu->pnext->name);
}

猜你喜欢

转载自blog.csdn.net/m0_49019274/article/details/114906899
今日推荐