64,647
社区成员
发帖
与我相关
我的任务
分享
template <typename elemType>
class list
{
public :
virtual void clear() = 0;
virtual int lenght()const = 0;
virtual void insert(int i, const elemType &x) = 0;
virtual void remove(int i) = 0;
virtual int search(const elemType &x)const = 0;
virtual elemType visit(int i)const = 0;
virtual ~list(){}
};
template <typename elemType>
class seqList : public list<elemType>
{
private :
elemType *data;
int currentLength;
int maxSize;
void doubleSpace();
public :
seqList(int initSize = 10);
~seqList() {delete [] data;}
void clear() {currentLength = 0;}
int length()const {return currentLength;}
void insert(int i, const elemType &x);
void remove(int i);
int search(const elemType &x)const;
elemType visit(int i)const {return data[i];}
void traverse()const;
};
template <typename elemType>
void seqList<elemType> :: doubleSpace() //扩容
{
;
}
template <typename elemType>
seqList<elemType> :: seqList(int initSize) //顺序表初始化
{
;
}
template <typename elemType> //在第i个位置插入元素
void seqList<elemType> :: insert(int i, const elemType &x)
{
;
}
template <typename elemType>
void seqList<elemType> :: remove(int i)
{
;
}
template <typename elemType>
int seqList<elemType> :: search(const elemType &x)const
{
;
}
template <typename elemType>
void seqList<elemType> :: traverse()const
{
;
}
void testForSeqList()
{
seqList<int> l;
cout << "currentLength : " << l.currentLength << endl;
cout << "maxSize : " << l.maxSize << endl;
l.insert(1, 1);
l.insert(1, 2);
l.insert(1, 3);
cout << "currentLength : " << l.currentLength << endl;
cout << "maxSize : " << l.maxSize << endl;
l.traverse();
l.remove(1);
l.traverse();
}
virtual int lenght()const = 0;
而派生类里面的是
int length()const {return currentLength;}
这样有一个函数还是纯虚的,就不能实例化了