C语言顺序表代码改错,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/21 12:53:29
以下顺序表有错,请高手改一下,并说明为什么错了,谢谢
#include <stdio.h>
#include <stdlib.h>

//——————————顺序表的动态分配的“存储结构”SqList————————————
#define LIST_INIT_SIZE 10
#define LIST_INCREMENT 1
typedef int ElemType;
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
//——————————“存储结构”构造完毕————————————

//——————————顺序表真正生成和初始化————————————
void InitList_Sq(SqList *L)///////////////////////////
{//生成一个顺序表,给它分配内存空间,并初始化生成的这个具体的存储结构中的相应的字段
L->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem)
{
printf("初始化分配内存失败!");
}

L->length=0;
L->listsize=LIST_INIT_SIZE;
}
//————————————————————————————————————————————

//———————————————插入元素——————————————————
void List_Insert_Sq(SqList *L,int i,ElemType e)//////////////////////////
{//在L这个存储结构中在第i个位置之前插入元素e
if(i

#include <stdio.h>
#include <stdlib.h>

#define LIST_INIT_SIZE 10
#define LIST_INCREMENT 10

typedef int ElemType;
typedef struct {
ElemType *elem;
int length;
int listsize;
}SqList;

// 初始化顺序表
void InitList_Sq(SqList *L)
{
L->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L->elem)
{
printf("allocate memory failed.\n");
exit(0);
}

L->length=0;
L->listsize=LIST_INIT_SIZE;
}

// 插入元素
void List_Insert_Sq(SqList *L,int pos,ElemType e)
{
int i;

if(pos<1 || pos>L->length+1)
{
printf("input a illegal data.\n");
exit(0);
}

if(pos==L->length+1)
L->elem[pos-1]=e;
else
{
i=L->length;