qq_莫非
#include<stdio.h>
#include<stdlib.h>
#define list_init_size 5
#define listincrement 10
#define overflow -2
typedef int status;
typedef int elemtype;
typedef struct
{
elemtype *elem;
int length;
int listsize;
} sqlist;
status initlist_sq(sqlist &L)
{
L.elem=(elemtype *)malloc(list_init_size * sizeof(elemtype));
if(!L.elem) exit(overflow);
L.length=0;
L.listsize=list_init_size;
return 1;
}
//链表初始化
#include <stdio.h>
#include <stdlib.h>
typedef int status;
typedef status elemtype;
typedef struct Lnode
{
elemtype date;
struct Lnode *next;
}Lnode , *linklist;
linklist L;
void createlist_L(linklist &L, int n)
{
linklist p;
L=(linklist)malloc(sizeof(Lnode));
L->next=NULL;
for (int i=n;i>0;--i)
{
p=(linklist)malloc(sizeof(Lnode));
printf("请输入链表的第%d个数!\n",i);
scanf("%d",&p->date);
p->next = L->next;
L->next = p;
}
}
在主函数直接调用,就会初始化为空了!!!
顺序表刚刚初始化要5个elemtype型空间,大于5的话,直接改#define list_init_size 5改为想要的大小
链表不需要要大小