课本简单程序执行

//线性表分为顺序表(定长),链表(不定长,可以申请新的储存空间)

include

using namespace std;
tempalte //假定顺序表的元素类型为T
class arrList:public List //顺序表,向量
{
private: //线性表的取值类型和取值空间
T*aList; //私有变量,储存顺序表的例
int Maxsize; //顺序表最大长度
int curLen; //顺序表当前长度
int position //私有变量,当前处理位置
public:
arrlist(const int size) //构建新的顺序表,参数为表实例的最大长度。
{
maxSize=size;
aList=new T[maxSize];
curlen=position=0;
}
~aList() //析构函数,用于消除该表。
{
delete[]aList;
}
void clear() //清空表中数据。
{
delete[]aList;
curlen=position=0;
aList=new T[maxSize];
}
};

//顺序表查找值为value的元素的位置
//成功返回ture,并将其元素下标保存到P中,失败则直接返回false

template
bool arrList::getPos(int &p,const T value)
{
int i; //设定一个整数,作为元素的下标
for(int i=0;i

猜你喜欢

转载自blog.csdn.net/CAUC_yangxiao/article/details/78196918