cilny 2013-09-30 00:20
浏览 983

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

#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;
}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog