请各位帮帮忙:看看为什么不能运行?
#include<iostream>using namespace std;
typedef int ElemType;
const int Maxsize=10;
typedef struct Sqlist
{
ElemType *elem;
int length;
int listsize;
}Sqlist;
void InitSqlist(Sqlist &L)
{
L.elem=new ElemType[Maxsize];
if(L.elem==0) exit(1);
L.length=0;
L.listsize=Maxsize;
}
void DestroySqlist(Sqlist &L)
{
delete[]L.elem;
L.elem=0;
L.length=L.listsize=0;
}
void ClearSqlist(Sqlist &L)
{
L.length=0;
}
int Sqlistlength(Sqlist& L)
{
return L.length;
}
int SqlistCapacity(Sqlist &L)
{
return L.listsize;
}
int SqlistEmpyt(Sqlist &L)
{
return L.length=0;
}
void EnlargeSqlist(Sqlist &L)
{
ElemType*newbase=new ElemType[2*L.listsize];
for(int i=0;i<L.length;i++)
newbase[i]=L.elem[i];
delete[]L.elem;
L.elem=newbase;
L.listsize=2*L.listsize;
}
void InsertSqlistAtNoi(Sqlist &L,int i,ElemType x)//Inserts an element in the ith position x
{
if(i<1||i>L.length) return ;
if(L.length==L.listsize)
EnlargeSqlist(L);
int j=L.length-1;
while(j>=i-1)
{
L.elem[j+1]=L.elem[j];
j--;
L.length++;
}
void DisplaySqlist(Sqlist &L)
{
for(int i=0;i<L.length;i++)
cout<<L.elem[i]<<" ";
cout<<endl;
}
int SqlistLocateNoi(Sqlist &L,int i,ElemType &x)//Searches the ith data element
{
if(i<1||i>L.length)
cout<<"Searches the position not to be illegal !"<<endl; return 0;
x=L.elem[i-1]; return 1;
}
int SqlistLocatex(Sqlist &L,ElemType x)//The search value is x data element
{
int i=1;
while(i<=L.length&&L.elem[i-1]!=x)
i++;
if(i<=L.length) return i;else return 0;
}
void test()
{
Sqlist L;
InitSqlist(L);
ElemType x;
int i;
cout<<"please enter 15 numbers:"<<endl;
for(i=0;i<15;i++)
{
cin>>x;
InsertSqlistAtNoi(L,L.length,x);
}
cout<<"now L is:"<<endl;
DisplaySqlist(L);
cout<<"Please input the serial number which must search :"<<endl;
cin>>i;
if(SqlistLocateNoi(L,i,x))
cout<<"This is the"<<i<<"element value is :"<<x<<endl;
else cout<<"There is no"<<i<<"element,Has surpassed 1 and"<<L.length<<"scope!"<<endl;
cout<<"Please input the serial number which must search :"<<endl;
cin>>i;
if(SqlistLocateNoi(L,i,x))
cout<<"This is the"<<i<<"element value is:"<<x<<endl;
else cout<<"There is no"<<i<<"element,Has surpassed 1 and"<<L.length<<"scope!"<<endl;
cout<<"Please input the serial number which must search:"<<endl;
cin>>i;
if(SqlistLocateNoi(L,i,x))
cout<<"This is the"<<i<<"element value is :"<<x<<endl;
else cout<<"There is no"<<i<<"element,Has surpassed" <<L.length<<"scope!"<<endl;
cout<<"Please input the element which must search :"<<endl;
cin>>x;
i=SqlistLocatex(L,x);
if(i)
cout<<x<<"is this"<<i<<"element"<<endl;
else cout<<"Does not have the value is "<<x<<"elements"<<endl;
cout<<"Please input the element which must search:"<<endl;
cin>>x;
i=SqlistLocatex(L,x);
if(i)
cout<<x<<"is this"<<i<<"element"<<endl;
else cout<<"Does not have the value is"<<x<<"elements"<<endl;
cout<<"Please input the element which must search:"<<endl;
cin>>x;
i=SqlistLocatex(L,x);
if(i)
cout<<x<<"is this"<<i<<"element"<<endl;
else cout<<"Dose not have the valude is"<<x<<"elements"<<endl;
}
int main()
{
test();
return 0;
}