顺序表的元素删除插入的问题
#include<iostream.h>
struct biao
{
int *p;
int length;
int chu;
};
class shunxu
{
public:
shunxu(biao& b)
{
b.length=0;
b.chu = 100;
b.p= new int[b.length];
}
void charu(biao& b,int l,int a)
{
for(int j=b.length-1;j>=l;j--)
{
b.p[j+1]=b.p[j];
}
b.p[l]=a;
b.length++;
}
void shanchu(biao& b,int i)
{
cout<<"你删除的是顺序表中的第"<<i+1<<"个数"<<b.p[i]<<endl;
for(int j = i;j<b.length;j++)
b.p[j]=b.p[j+1];
b.length--;
}
void hebing(biao& b,biao& a)
{
int i=0;
for(int j=b.length;j<(b.length+a.length);j++)
{
b.p[j]=a.p[i];
i++;
}
b.length+=a.length;
delete a.p;
}
void disp(biao& b)
{
cout<<"现在要输出的顺序表是:"<<endl;
for(int m=0;m<b.length;m++)
{
cout<<b.p[m]<<" ";
}
}
};
void main()
{
biao b1,b2;
shunxu ab(b1);
shunxu ab1(b2);
for(int i=0;i<5;i++)
{
b1.p[i]=i+5;
b1.length++;
}
for(int j= 0;j<5;j++)
{
b2.p[j] = j+2;
b2.length++;
}
ab.shanchu(b1,3);
ab.disp(b1);
ab.disp(b2);
ab.charu(b2,1,7);
ab.disp(b2);
ab.hebing(b1,b2);
ab.disp(b1);
}
总是找不到错误,提示是内存的问题。大家帮忙看一下~