apprentices 2016-03-13 04:50 采纳率: 0%
浏览 1332

数据结构关于输出的问题,求老司机指路

#include

#include

using namespace std;

template

class SeqList

{

protected:

T *element;

int length;

int n;

private:

void init(T value[],int n);

public:

SeqList(int length = 32);

SeqList(int length, T n);

SeqList(T value[], int n);

~SeqList();


bool empty();

int  count();

T & operator [](int i);

friend ostream& operator <<<>(ostream&, SeqList<T>&);

void priintPrevious();

void insert(int i,T x);

virtual void insert(T x);

T remove(int i);

void removeAll();

virtual int search(T key, int start = 0);

virtual void removeFirst(T key);


SeqList(SeqList<T>&list);

SeqList<T>&operator =(SeqList<T>&list);

bool operator==(SeqList<T>&list);

bool operator!=(SeqList<T>&list);

void operator+=(SeqList<T>&list);

SeqList<T>operator+(SeqList<T>&list);

};
template
SeqList ::SeqList(int length) //构造空顺序表,length指定数组容量

{
if (length < 0)

    length = 0;

this->element = new T[length];

this->length = length;

this->n = 0;                                //元素个数为0

}

template

SeqList ::SeqList(int length, T n) //构造顺序表,length个元素为X,构造函数重载
{

this->element = new T[length];

this->length = this->n = length;

for (int i; i < this->n; i++)

    this->element[i] = x;                   //执行T的幅值

}

template

SeqList ::SeqList(T value[], int n) //构造顺序表,由value数组提供元素,n指定元素个数

{
this->init(value, n);
}

template

void SeqList ::init(T value[], int n) //初始化顺序表

{
this->length = n * 2;

this->element = new T[this->length];

this->n = n;

for (int i = 0; i < n; i++)

    this->element[i] = value[i];

}
template

SeqList ::~SeqList() //析构函数

{
delete[]this->element; //释放掉element所占用的内存

}
//template

//template
int main()
{
int value[3] = {0,1,2};
SeqList seqlist(int value,int n=3);
cout<<<element[2]; //这里的输出语句如何写

return 0;

}

  • 写回答

2条回答

  • cp钊 2016-03-13 15:16
    关注

    你的变量为protect,外部访问不了,可以专门写个public函数来返回类的element的值

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序