那位大侠帮忙看一下错误!!
#define maxsize 100#include<stdio.h>
#include<iostream.h>
typedef int elemtype;
typedef struct
{
elemtype data[maxsize];
int length;
}sqlist;
void initlist(sqlist &l)
{
l.length =0;
}
int data[maxsize];
void creatsqlist(sqlist &l,int n)
{
int i;
for(i=0;i<n;i++)
cin>>data[i];
l.length =n;
fflush(stdin);
}
void output(sqlist l)
{
int i;
for(i=0;i<l.length ;i++)
cout<<data[i]<<endl;
}
int isempty(sqlist l)
{
if(l.length ==0)return 1;
else return 0;
}
int getelem(sqlist l,int i)
{
if(i<0||i>=l.length ) return -1;
else return l.data [i];
}
int locateelem(sqlist l,elemtype x)
{
int k=0;
while(k<l.length && l.data [k]!=x)
k++;
if(k<l.length)return k;
else return -1;
}
int insert(sqlist &l,elemtype x,int i)
{
int k;
if(i<0||i>l.length ||l.length==maxsize)
return 0;
else
{for(k=l.length ;k>=i;k--)
l.data [k]=l.data [k-1];
l.data [i]=x;
l.length =l.length +1;
}
return 1;
}
int DELETE(sqlist &l,int i)
{int k;
if(i<0||i>=l.length )
return 0;
else
{for(k=i;k<l.length ;k++)
l.data [k]=l.data [k+1];
l.length --;
}
return 1;
}
//ok
void clear(sqlist &l)
{
initlist(l);
}
void margelist(sqlist la,sqlist lb,sqlist &lc)
{
int i,j,k;
i=j=k=0;
while(i<la.length &&j<lb.length )
if(la.data [i]<lb.data [j])
lc.data [k++]=la.data [i++];
else if(la.data [i]>lb.data [j])
lc.data [k++]=lb.data [j++];
else
{lc.data [k++]=lb.data [j++];
i++;
}
while (i<la.length )
lc.data [k++]=la.data [i++];
while(j<lb.length )
lc.data [k++]=la.data [j++];
lc.length =k;
}
//ok
void output()
{
int i;
for(i=0;i<10;i++)
cout<<" ";
for(i=0;i<32;i++)
cout<<"*"<<endl;
}
void mainpp()
{
int i;
//output();
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"1.建立一个顺序表"<<"*"<<endl;
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"2.输出一个顺序表 "<<"*"<<endl;
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"3.在顺序表中查找 "<<"*"<<endl;
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"4.向顺序表中插入一个元素 "<<"*"<<endl;
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"5.删除顺序表中的一个元素 "<<"*"<<endl;
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"6.从顺序表中取出一个元素 "<<"*"<<endl;
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"7.将两个顺序表合并 "<<"*"<<endl;
for(i=0;i<10;i++) cout<<" ";cout<<"*"<<"0.退 出 "<<"*"<<endl;
for(i=0;i<8;i++) cout<<" ";cout<<"*"<<endl;
//output();
}
//ok
void main()
{
int n,i,k=1,m,x;
sqlist l,la,lc;
initlist (l);
mainpp();
while(k)
{cout<<"请选择0--7: "<<endl;
cin>>m;
getchar();
switch(m)
{
case 0: return;
case 1:{
cout<<"输入元素值,构成顺序表:"<<endl;
cout<<"请输入顺序表元素的个数:";
cin>>n;
creatsqlist(l,n);
output(l);
break;
}
case 2: output(l);cout<<endl;break;
case 3:{
cout<<"请输入要查找的元素值 :";
cin>>x;
k=locateelem(l,x);
cout<<"要查找的元素的定位:"<<endl;
break;
}
case 4:{
cout<<"输入要插入元素的位置及其值:";
fflush(stdin);
cin>>i;
cin>>x;
insert(l,x,i);
output(l);
cout<<endl;
break;
}
case 5:
{
cout<<"输入要删除元素的位置:";
fflush(stdin);
cin>>i;
output(l);
break;
}
case 6:
{
cout<<"请输入要取出的元素的序号:";
fflush(stdin);
cin>>i;
k=getelem(l,i);
cout<<" 取出的第"<<i<<"个元素的序号:";
break;
}
case 7:{
initlist(la);
cout<<" 请输入第2个顺序表元素的个数:";
cin>>m;
creatsqlist(la,m);
output(la);
margelist(l,la,lc);
cout<<"输出合并后的顺序表中的元素 :"<<endl;
output(lc);
break;
default :return;
}
cout<<" 继续运行吗Y(1)/N(0) :";
cin>>k;
if(!k) return ;
}
}