线性表作为一种线性数据结构,常应用于信息检索,存储管理等诸多领域,因此了解线性表的基本操作与应用对于我们学习数据结构有着十分重要的意义。
一,线性表的基本操作
首先,我们定义一个线性表的基类linearlist,并以此定义了它的派生类顺序表类seqlist和链表类singlelist.在基类中,我们以抽象函数的形式定义了线性表常用的几种操作,如插入删除等。
#ifndef LINEARLIST_H_INCLUDED #define LINEARLIST_H_INCLUDED #include<iostream> using namespace std; template<class T> 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; }; #endif // LINEARLIST_H_INCLUDED