用c语言实现线性表的构建,插入,删除操作。#include
#include
#define LIST_INIT_SIZE 10 //初始分配存储空间
#define OVERFLOW 1 //存储空间分配增量
#define LISTINCREMENT 8
typedef int Elemtype;
typedef struct
{
Elemtype *elem;//基址
int size; //当前储存空间
int len; //当前长度
}Sqlist;
void Initlist_sq(Sqlist &L)//创建线性表
{
L.elem=(int )malloc(LIST_INIT_SIZEsizeof(int));
if(!L.elem) exit(OVERFLOW);//储存空间分配失败
L.len=0; //空表长度初始化为0;
L.size=LIST_INIT_SIZE;
}
void Listinsert_sq(Sqlist &L,int i,int e)//线性表插入
{
int *newbase,*p,*q;
if(i<1||i>L.len+1) printf("插入错误");
if(L.len>=L.size)
{
newbase = (Elemtype *)realloc(L.elem,
(L.size + LISTINCREMENT)*sizeof(Elemtype));
if(!newbase)exit(OVERFLOW);
L.elem=newbase;
L.size+=LISTINCREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.len-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++L.len;
printf("插入成功");
}
void Listdelete_sq(Sqlist &L,int i)//线性表删除
{
int e,*p,*q;
if(i<1||i>L.len+1) printf("错误");
p=&(L.elem[i-1]);
e=*p;
q=L.elem+L
有什么疑问?是不会调用函数还是?