操作顺序表应包含什么头文件啊?
发布网友
发布时间:2022-05-30 08:28
我来回答
共1个回答
热心网友
时间:2023-10-16 06:10
最好把程序附上
#include<iostream>
using namespace std;
const int MaxSize=20;
template<class T>
class SeqList
{
public:
SeqList(){lengh=0;}
SeqList(T a[],int n);
~SeqList(){}
T Get(int i);
int Locate(T x);
Insert(int i,T x);
T Delete(int i);
void PrintList();
private:
T data[MaxSize];
int length;
};
SeqList<int>::SeqList(T a[],int n)
{
if(n>MaxSize) throw "参数非法";
for (int i=0;i<n;i++)
data[i]=a[i];
length=n;
}
SeqList<int>::Insert(int i,T x)
{
if(length>=MaxSize) throw "上溢";
if(i<1||i>length+1) throw "位置异常";
for(int j=length;j>=i;j--)
data[j]=data[j-1];
data[j-1]=x;
length++;
}
SeqList<int>::Delete(int i)
{
if(length==0) throw "下溢";
if(i<1||i>length+1) throw "位置异常";
for(int j=i;j<length;j++)
data[j-1]=data[j];
length--;
return length;}
http://apps.hi.baidu.com/share/detail/8930797
http://haofu123.blog.163.com/blog/static/1782949200910103422303/
http://zhidao.baidu.com/question/26717880.html?fr=ala0
希望对你有用