#include<stdio.h>
#include<stdlib.h>
//头插法创建节点,一般不用
typedef struct Lnode{
int *data;
struct Lnode *next;
}Lnode,*list;
list creat(list &L)//&L为引用型变量,C语言不可用,此处为C++语法,考试也算正确
{
Lnode *s; int x;
L = (list)malloc(sizeof(Lnode));//创建头节点 固定模式 必背
L->next = NULL;
scanf("%d", &x);
while (x!=9999)
{
s = (list)malloc(sizeof(Lnode));
s->data = x;
s->next = L->next
L->next = s;
scanf("%d", &x);
}
return L; //循环结束
}
//接下来是尾插法,经常用,需要记住
list creat2(list &L)
{
int x;
Lnode *s, *r;
*r = L;
L = (list)malloc(sizeof(Lnode));
scanf("%d", &x);
while (x!=9999)
{
s = (list)malloc(sizeof(Lnode));
s->data = x;
r->next = s;
r = s;
scanf("%d", &x);
}
r->next = NULL;
return L;
}