为什么运行到一半的时候就自动结束了呢
#include <iostream>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
#define MAXSIZE 100
typedef struct
{
ElemType *elem;
int length;
}SqList;
Status InitSqList(SqList &L)
{
L.elem=new ElemType[MAXSIZE];
if(L.elem=NULL)exit(OVERFLOW);
L.length=0;
return OK;
}
Status CreateSqList(SqList &L,int n)
{
for(int i=0;i<n;i++)
cin>>L.elem[i];
L.length=n;
return OK;
}
void TraverSqList(SqList L)
{
cout<<"顺序表中的元素为:";
for(int i=0;i<L.length;i++)
cout<<L.elem[i]<<" ";
cout<<endl;
}
Status LocateElem(SqList L,ElemType &e)
{
for( int i=0;i<L.length;i++)
if(L.elem[i]==e)
return i+1;
return 0;
}
Status InsertList(SqList &L,int i,ElemType e)
{
if(i<1||i>L.length)
return ERROR;
if(i>L.length==MAXSIZE)
return ERROR;
for(int j=L.length-1;j>=i-1;j--)
L.elem[j+1] =L.elem[j];
L.elem[i-1]=e;
++L.length;
return OK;
}
Status DeleteList(SqList &L,int i)
{
if(i<1||i>L.length)
return ERROR;
for(int j=i;j<L.length-1;j++)
L.elem[j-1]=L.elem[j];
--L.length;
return OK;
}
void menu()
{
cout<<" ************ "<<endl;
cout<<" 0:退出 "<<endl;
cout<<" 1:初始化 "<<endl;
cout<<" 2:建表 "<<endl;
cout<<" 3:遍历 "<<endl;
cout<<" 4:按值查找元素 "<<endl;
cout<<" 5:插入 "<<endl;
cout<<" 6:删除 "<<endl;
cout<<" *********** "<<endl;
}
int main()
{
SqList L;
int choose,i,e,n;
menu();
while(1)
{
cout<<"选择要执行的基本操作:";
cin>>choose;
switch(choose)
{
case 1:
InitSqList(L);
break;
case 2:
cout<<"输入表中元素个数:";
cin>>n;
CreateSqList(L,n);
break;
case 3:
TraverSqList(L);
break;
case 4:
cout<<"输入要查找元素的值:"<<endl;
cin>>e;
if(LocateElem(L,e))
cout<<"该元素的位置是第"<<LocateElem(L,e)<<"位"<<endl;
else
cout<<"该元素不存在!"<<endl;
break;
case 5:
cout<<"输入要插入元素的位置和值:"<<endl;
cin>>i>>e;
if(InsertList(L,i,e)==OK)
TraverSqList(L);
else
cout<<"不能插入!"<<endl;
break;
case 6:
cout<<"输入要删除元素的位置:"<<endl;
cin>>i;
if(DeleteList(L,i)==OK)
TraverSqList(L);
else
cout<<"删除位置不合法"<<endl;
break;
case 0:
cout<<"操作结束"<<endl;
exit(0);
}
}
return OK;
}