?? creat.c
字號(hào):
#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就立刻指向了最后的節(jié)點(diǎn)
n=n+1;
if(n>MAX)
continue; //continue放在這個(gè)位置可以減少不必要的節(jié)點(diǎn)申請(qǐng),減少內(nèi)存浪費(fèi)
p1=(struct student * )malloc( LEN ); //再新申請(qǐng)節(jié)點(diǎn)
scanf("%ld",&p1->num);
}
p2->next=NULL;
n=n-1;
return head;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -