请教高手,这个程序为什么编译能通过,但执行却有问题,错哪了?请问高手无比感谢!!

[复制链接]
查看11 | 回复4 | 2011-9-25 12:32:08 | 显示全部楼层 |阅读模式
#includeiostream#defineMAXSIZE11usingnamespacestd;typedefstruct{intdata[MAXSIZE];intlast;}SeqList;intInsert_SeqList(SeqList*L,inti,intx){intj;if(L-last==MAXSIZE-1){cout\"表满\"endl;return-1;}if(i1||iL-last2){cout\"位置错\"endl;return0;}for(j=L-last;j=i-1;j--)L-data[j1]=L-data[j];L-data[i-1]=x;L-last;return1;}intmain(){SeqList*L;system(\"color2E\");inti;intx;intdata[MAXSIZE]={1,23,3,5,5,3,32,34,354,34,34};for(intm=0;mMAXSIZE;m)coutdata[m]\"\";coutendl\"请输入在第几个位置插入:\";cini;coutendl\"请输入插入的数字:\";cinx;Insert_SeqList(L,i,x);break;for(intn=0;nMAXSIZE1;n)coutdata[n]\"\";coutendl;return0;}
回复

使用道具 举报

千问 | 2011-9-25 12:32:08 | 显示全部楼层
已改,如下#includeiostream#defineMAXSIZE12usingnamespacestd;typedefstruct{intdata[MAXSIZE];intlast;}SeqList;intInsert_SeqList(SeqList*L,inti,intx){intj;if(L-last==MAXSIZE){cout\"表满\"endl;return0;}if(i1||iL-last2){cout\"位置错\"endl;return0;}L-last==MAXSIZE;for(j=L-last;ji-1;j--)L-data[j]=L-data[j-1];L-data[i-1]=x;L-last;return1;}intmain(){SeqList*L;system(\"color2E\");inti;intx;SeqListdata[MAXSIZE]={1,23,3,5,5,3,32,34,354,34,34};L=data;L-last=11;for(intm=0;mMAXSIZE-1;m)coutL-data[m]\"\";coutendl\"请输入在第几个位置插入:\";cini;coutendl\"请输入插入的数字:\";cinx;Insert_SeqList(L,i,x);for(intn=0;nMAXSIZE;n)coutL-data[n]\"\";coutendl;return0;}
回复

使用道具 举报

千问 | 2011-9-25 12:32:08 | 显示全部楼层
Insert_SeqList(L,i,x);break;这个调用时,L有赋初值吗?追问L不是指针吗?
回复

使用道具 举报

千问 | 2011-9-25 12:32:08 | 显示全部楼层
指针在使用前要赋初值,即要知道指向哪里
回复

使用道具 举报

千问 | 2011-9-25 12:32:08 | 显示全部楼层
逻辑混乱,你的intdata[MAXSIZE]={1,23,3,5,5,3,32,34,354,34,34};与结构体中的data根本没有关系。建议理清思路后再去重写。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行