⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 creat.c

📁 一个有关linux下面Makefile与链表结合的演示程序
💻 C
字号:
#include<stdio.h>
#include<stdlib.h>
#include"def.h"
#define LEN sizeof(struct student)


struct student * creat(int MAX)
{
	struct student *head;
	struct student *p1;
	struct student *p2;
	n=1;
	p1=p2=(struct student *)malloc(LEN);
	scanf("%ld",&p1->num);
	head=p1;
		while((p1->num!=0)&&(n<(MAX+1)))
			{

					if(n==1)
							head=p1;
					p2->next=p1;
					p2 = p1;//链接上以后P2就立刻指向了最后的节点
					n=n+1;

							if(n>MAX)
							continue; //continue放在这个位置可以减少不必要的节点申请,减少内存浪费
							p1=(struct student * )malloc( LEN ); //再新申请节点
							scanf("%ld",&p1->num);


			}
	p2->next=NULL;
	n=n-1;
	return head;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -