顺序表模板C++
来源:互联网 发布:js请求url获取返回值 编辑:程序博客网 时间:2024/06/04 18:11
C++ 顺序表模板
#include <iostream>template<class T> class SeqList { private: T *elem; int length; int MaxSize; public: SeqList(int InitSize); ~SeqList(); void Clear(); bool IsEmpty() const { return (length == 0); } bool IsFull() const { return(length == MaxSize); } int Length() const; T Get(int i) const; int Next(int i) const; int Prior(int i)const; int Find(T e)const; int Insert(int i, const T &e); int Delete(T &e, int i); };template <class T>SeqList<T>::SeqList(int InitSize){ if (InitSize > 0) { elem = new T[InitSize]; Exception(!elem, "there is no space in memory"); length = 0; MaxSize = InitSize - 1; }}template<class T>SeqList<T>::~SeqList(){ delete[] elem;}template<class T>void SeqList<T>::Clear(){ length = 0;}template<class T>int SeqList<T>::Length() const{ return length;}template<class T>T SeqList<T>::Get(int i) const{ Exception((i < 1) || (i > length), "out of bounds access"); return elem[i];}template<class T>int SeqList<T>::Next(int i)const{ Exception((i<1) || (i>length - 1), "Out of bounds access"); return i + 1;}template<class T>int SeqList<T>::Prior(int i)const{ Exception((i <= 1) || (i > length), "Out of bounds access"); return i - 1;}template<class T>int SeqList<T>::Find(T e) const{ elem[0] = e; int i = length; while (elem[i] != e) i--; return i;}template<class T>int SeqList<T>::Insert(int i, const T &e){ Exception((i<1) || (i>length + 1), "i is not correct"); Exception(MaxSize == length, "no space for new item"); for ( int j = length; j >= i; j--) elem[j + 1] = elem[j]; elem[i] = e; length++; return 1;}template <class T>int SeqList<T>::Delete(T &e, int i){ Exception((i<1) || (i>length), "i is illgeal"); e = elem[i]; for (int j = i; j < length; j++) elem[j] = elem[j + 1]; length--; return i;}
0 0
- 【C++】模板类顺序表
- c++(模板类)实现顺序表
- 【C++】用模板实现顺序表
- 【C++】用模板实现顺序表Vector
- [数据结构] 顺序表的实现(c++/类模板)
- 模板顺序链表
- 顺序表模板C++
- 模板实现顺序表
- 顺序表模板
- 模板实现顺序表
- C++模板顺序表
- 模板实现顺序表
- 模板顺序表
- 顺序表类模板
- 顺序表---模板
- 模板实现顺序表
- 顺序表类模板
- 顺序表类模板
- 在码神四天的学习总结
- CSS的一些小的注意点整理
- [Android]百度地图之POI检索
- java随机数生成算法
- gem 镜像安装--这个坑必须记住
- 顺序表模板C++
- quick lua-binding使用详解
- VS搭载SQL 常用语句 (1)
- APIStore使用例子(获取易源笑话)
- javascript和python写的选择排序算法
- 打开保存对话框(saveFileDialog和openFileDialog控件)
- 【HDU】 1333 Smith Numbers
- 简单dp
- Ubuntu10.04下安装tftp服务器