#include"stdio.h"
#include"stdlib.h"
typedef struct node
{
int data;//结点所对应的数据
struct node* Next;//指向下一个结点的指针next
}l, * list;
list H;
list makebiao(int n)//n为元素个数
{
int i;
list H;
H = (list)malloc(sizeof(l));
H->Next= (list)malloc(sizeof(l));
H->data = 0;
list p = H->Next;
p->Next= (list)malloc(sizeof(l));
for (i = 1; i < n; i++)
{
p->data = i;
p = p->Next;
}
return H;
}
void destroy(list* H)
{
list p, q;
p = *H;
while (p)
{
q = p;
p = p->Next;
free(q);
}
*H = NULL;
}
list insert(list H, int x)
{
list p, q;
p = (list)malloc(sizeof(l));
q = (list)malloc(sizeof(l));
for (p = H; p->Next->data <= x; p = p->Next)
{
}
q->data = x;
q->Next = p->Next;
q = p->Next;
return H;
}
void putbiao(list H)
{
while (H)
{
printf("%d\t", H->data);
H = H->Next;
}
}
int main()
{
list H;
H = makebiao(99);
putbiao(H);
insert(H, 5);
putbiao(H);
destroy(&H);
return 1;
}
报错图片
用的是VS2019