ljq_neversaydie 2015-11-02 08:39 采纳率: 0%
浏览 1388

数据结构顺序表debug assertion failed

//文件linearlist.h
#include
template
class LinearList
{
public:
virtual bool Isempty()const=0;
virtual int Length()const=0;
virtual bool Find(int i,T &x)const=0;
virtual int Search(T x)const=0;
virtual bool Insert(int i,T x)=0;
virtual bool Delete(int i)=0;
virtual bool Update(int i,T x)=0;
virtual void Output(ostream& out)const=0;
protected:
int n;
};

//文件seqlist.h
#include"linearlist.h"
template
class SeqList:public LinearList
{
public:
SeqList(int mSize);
~SeqList(){delete [] elements;}
bool Isempty()const;
int Length()const;
bool Find(int i,T& x)const;
int Search(T x)const;
bool Insert(int i,T x);
bool Delete(int i);
bool Update(int i,T x);
void Output(ostream& out)const;
void Reverse();
bool DeleteX(const T& x);
private:
int maxLength;
T *elements;
};
template
SeqList::SeqList(int mSize)
{
maxLength=mSize;
elements=new T[maxLength];
n=0;
}
template
bool SeqList::Isempty()const{return n==0;}
template
int SeqList::Length()const{return n;}
template
bool SeqList::Find(int i,T& x)const
{
if(in-1)
{
cout<<"Out of Bounds"< return false;
}
x=elements[i];
return true;
}
template
int SeqList::Search(T x)const
{
for(int j=0;j if(elements[j]==x)
return j;
return -1;
}
template
bool SeqList::Insert(int i,T x)
{
if(i<-1||i>n-1)
{
cout<<"Out of Bounds"< return false;
}
if(n==maxLength)
{
cout return false;
}
for(int j=n-1;j>i;j--)
elements[j+i]=elements[j];
elements[i+1]=x;
n++;
return true;
}
template
bool SeqList::Delete(int i)
{
if(!n)
{
cout<<"UnderFlow"< return false;
}
if(in-1)
{
cout<<"Out of Bounds"< return false;
}
for(int j=i+1;j elements[j-1]=elements[j];
n--;
return true;
}
template
bool SeqList::Update(int i,T x)
{
if(in-1)
{
cout<<"Out of Bounds"< return false;
}
elements[i]=x;
return true;
}
template
void SeqList::Output(ostream& out)const
{
for(int i=0;i out out }
template
void SeqList::Reverse()
{
int x;
for(int j=0;j<=n/2;j++)
{
x=elements[j];
elements[j]=elements[n-1-j];
elements[n-1-j]=x;
}
}
template
bool SeqList::DeleteX(const T& x)
{
int booln=n;
for(int i=0;i<n;i++)
if(elements[i]==x)
{
Delete(i);
i--;
}
if(booln!=n)
return true;
return false;
}

//main函数
#include"seqlist.h"
const int SIZE=20;
template
void Union(SeqList &LA,SeqList LB)
{
T x;
for(int i=0;i {
LB.Find(i,x);
if(LA.Search(x)==-1)
LA.Insert(LA.Length()-1,x);
}
}
void main()
{
SeqList LA(SIZE);
SeqList LB(SIZE);
cout<<"Please input LA:";
for(int i=-1;i {
int n;
cin>>n;
LA.Insert(i,n);
}
cout<<"Please input LB:";
for(i=-1;i {
int n;
cin>>n;
LB.Insert(i,n);
}
Union(LA,LB);
LA.Output(cout);
// Same(LA,LB);
// LA.Output(cout);
// Different(LA,LB);
// LA.Output(cout);
return;
}
图片说明

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?