chain是个自定义的类 template<class T>
struct chainNode{//结构体也能构造 成员,函数
T element;
chainNode<T> *next;
chainNode(){}
chainNode(const T& element){ this->element= element;}
chainNode(const T& element,chainNode<T> * next){
this->element= element;
this->next=next;
}
};
template<class T>
class chain : public linearList<T>{//抽象类的派生类
public:
chain(int init =10);
chain(const chain<T>&);
~chain();
bool empty() const {return listSize == 0;}//1
int size() const {return listSize ;} //1
T& get(int theIndex) const;//返回索引的元素
int indexOF(const T& theElment) const;//第一次出现的索引
void erase(int theIndex);
void insert(int theIndex,const T& theElement);
void output(ostream & out) const;
void swap(chain<T>& theChain);//交换两个链表
// /////习题
void setSize(int theSize);//若多于 则删除 1
void set(int theIndex,T theElement);//置换索引元素
int lastIndexOf(T theElement);//元素最后出现索引
void removeRange(int fromIndex,int toIndex);//删除索引范围内的所有节点
T& operator[](int index);
bool operator==(chain<T> & x);
bool operator!=(chain<T>& x);
bool operator<(chain<T>& x);
void leftShift(int i);//左移动元素 (删除—)
void reverse();//颠倒元素顺序
void meld(chain<T>& a,chain<T>& b);//交替合并
void clean();//清空
void merge(chain<T>& a,chain<T>& b);//有序合并
void split(chain<T>& a,chain<T>& b);//分奇偶索引
void circularShift(int i);//向左循环索引
void insertSort();//链表排序
///////////////
friend ostream& operator<<(ostream& out,const chain<T>& x){ x.output(out); return out;}
protected:
void checkIndex(int theIndex) const;
chainNode<T>* firstNode;
int listSize;
};
|