List(2)List的顺序实现
来源:互联网 发布:大智慧贵金属分析软件 编辑:程序博客网 时间:2024/06/05 17:35
list.h
/*----------------------------------------------- Created By EverSteins Email:EverSteins@gmail.com 转载请注明出处 ------------------------------------------------*/ template<class List_entry>class List{public:List():count(0);int size() const;bool full() const;bool empty() const;void clear();void traverse(void (*visit)(List_entry&));Error_code retrieve(int position,List_entry &x)const;Error_code replace(int position,const List_entry &x);Error_code remove(int position,List_entry &x);Error_code insert(int position,const List_entry &x);protected:int count;List_entry entry[max_list];};
list.cc
/*----------------------------------------------- Created By EverSteins Email:EverSteins@gmail.com 转载请注明出处 ------------------------------------------------*/ #include "list.h"template<class List_entry>int List<List_entry>::size() const{return count;}template<class List_entry>bool List<List_entry>::full() const{return count>=max_list;}template<class List_entry>bool List<List_entry>::empty() const{return count<=0;}template<class List_entry>void List<List_entry>::clear(){count=0;}template<class List_entry>void List<List_entry>::traverse(void (*visit)(List_entry&)){for (int i=0;i<count;i++)(*visit)(entry[i]);}template<class List_entry>Error_code List<List_entry>::insert(int position,const List_entry &x){if (full())return overflow;if (position < 0 || position > count)return range_error;for (int i=count-1;i>=position;i--)entry[i+1]=entry[i];entry[position]=x;count++;return success;}template<class List_entry>Error_code List<List_entry>::remove(int position,List_entry &x){if (empty())return underflow;if (position<0 || position>=count)return range_error;x=entry[position];for (int i=position;i<count-1;i++)entry[i]=entry[i+1];count--;return success;}template<class List_entry>Error_code List<List_entry>::retrieve(int position,List_entry &x)const{if (position<0 || position>=count)return range_error;x=entry[position];return success;}template<class List_entry>Error_code List<List_entry>::replace(int position,const List_entry &x){if (position<0 || position>=count)return range_error;entry[position]=x;return success;}
- List(2)List的顺序实现
- 顺序容器 list 2
- 建议采用的顺序是 List<T>、List<?>、List<Object>
- 子list中的顺序会影响list的顺序问题
- 常用数据结构之顺序结构List实现
- List(1)List单链表的链式实现
- list的实现
- list 方法的实现
- list 方法的实现
- list 方法的实现
- list 方法的实现
- list容器的实现
- python list的实现
- list 的c实现
- list的实现
- List数据结构的实现
- list的一种实现
- [STL]List的实现
- xp安装iis6无法复制文件admexs.dll
- Android中Task、Activity、BackStack(栈)的关系
- linux驱动头文件说明
- SQL语言基础使用
- 预编译(二)
- List(2)List的顺序实现
- s3c6410_地址映射
- Linux下搭建Qt+OpenGL .
- VC中使用ADO因获取值为空而出现运行时错误【解决方法】
- Linux vi 按键键盘映射表
- Shell之 find -exec -ok 的用法
- java web中IBATIS的工作原理(1)
- 暗时间-我不想与我不能
- 去除vss源代码管理