2 u011652553 u011652553 于 2013.09.30 08:20 提问

顺序表的插入输出不了?不明白。初学者,望各位赐教。

#include
using namespace std;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OVERFLOW -1
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sp(SqList &l)
{
l.elem=new int[100];
if(!l.elem)exit(OVERFLOW);
l.listsize=LIST_INIT_SIZE;
return 0;
}
int insert(SqList &l,int i,int &e)
{

if(il.length+1)return -1;
if(l.length>=l.listsize)
{
int *newbase;
newbase=new int[110];
if(!newbase)
exit(OVERFLOW);
l.elem=newbase;
}
int *p;
int *q=&(l.elem[i-1]);
for(p=&(l.elem[l.length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++l.length;
cout<<"the e"<<l.elem[i-1];
return e;
}
int chuangjian(SqList &l)
{

int i;

InitList_Sp(l);
cout<<"please input the number of the data "<<endl;

cin>>i;
cout<<"now you can input them"< for(int j=0;j {
cin>>l.elem[j];
}
return 0;
}
int main()
{
SqList l;
chuangjian(l);
int e;
cout<<"please input the number you want to insert"<<endl;

cin>>e;

int j;
cout<<"please input the location you want to put"<<endl;

cin>>j;
insert(l,j,e);
return 0;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!