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 Arcgis相交分析无法绘制一个或多个图形
    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)