求指教,代码完全比着
```敲的,没有出现错误,但是运行不出结果,就出现这个界面,一碰就退出
#include<stdio.h>
#include<stdlib.h> //malloc
#include<math.h> //OVERFLOW
#define LIST_INIT_SIZE 100 //初始化最大空间
#define LISTINCREMENT 10 //增量
#define OK 1
#define ERROR 0
//讨论的int
typedef int ElemType; //数据元素类型
typedef int Status; //函数的返回值状态
//顺序表类型定义
typedef struct
{
ElemType *elem; //顺序表的起始地址
int length; //元素个数
int listsize; // 当前容量大小
}SqList;
//---------------相关操作-----------------
//初始化操作
Status ListInt_Sq(SqList &L) //输入型 输出型
{
//1:申请空间malloc
L.elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!0) exit(OVERFLOW);
//2: length
L.length=0;
//3: 设定当前容量大小
L.listsize= LIST_INIT_SIZE;
return OK;
}
//插入操作
//1:含义
//2:算法思想
Status ListInsert_Sq(SqList &L,int i,ElemType e)
{
ElemType *mewbase;
int n=L.length;
int j;
//i的合法性
if(i<1 || i>n+1 ) return ERROR;
//满的情况
if(n>=L.listsize)
{
//重新申请空间 realloc
mewbase=(ElemType*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType));
if(!mewbase) exit(OVERFLOW);
//将新地址赋值给L.elem
L.elem=mewbase;
//设定当前容量大小
L.listsize+=LISTINCREMENT;
}
//元素移动
for(j=n-1;j>=i-1;j--)
{
//指针[下标]
//把[j]的元素后移一个位置[j+1]
L.elem[j+1]=L.elem[j];
}
//放元素
L.elem[i-1]=e;
//表长加1
L.length++;
return OK;
}
Status ListDelete_Sq(SqList &L,int i,ElemType &e)
{
int n=L.length;
int j;
//1:删除位置i的合法范围[1,n]
if(i<1||i>n) return ERROR;
//2:保留删除元素
e=L.elem[i-1];
//3:从第i+1个位置开始,直到an,都往前移动一格位置
for(j=i;j<=n-1;j++)
{
//把[j]元素往前移动一个位置([j-1])
L.elem[j-1]=L.elem[j] ;
}
//4:表长减一
L.length--;
return OK;
}
int main()
{
SqList L; //定义顺序表L
ElemType e;//定义元素类型的变量
//建表
ListInt_Sq(L) ; //函数调用
//在第一个位置插入一个元素10
printf("在第一个位置插入一个元素10\n") ;
ListInsert_Sq(L,1,10);
printf("在第2个位置插入一个元素20\n") ;
ListInsert_Sq(L,2,20);
printf("在第3个位置插入一个元素30\n") ;
ListInsert_Sq(L,3,30);
printf("[1]:%d",L.elem[1]);
printf("长度:%d\n",L.length);
printf("删除第二个位置的元素:%d\n");
ListDelete_Sq(L,2,e);
printf("%d",e) ;
printf("长度:%d\n",L.length);
return 0;
}
