间接寻址
来源:互联网 发布:家电设计软件 编辑:程序博客网 时间:2024/04/27 21:11
间接寻址是公式化描述和链表描述的组合。
大多数间接寻址链表操作的时间复杂性都与元素的总数无关。
在间接寻址方式中,使用一个指针表来跟踪每个元素。可采用一个公式来定位每个指针的位置,以便找到所需要的元素。元素本身可能存储在动态分配的节点或节点数组之中。
间接寻址的类定义及其操作
#pragma oncetemplate<class T>class IndirectList {public: IndirectList(int MaxListSize = 10); ~IndirectList(); bool IsEmpty() const { return length == 0; } int Length() const { return length; } bool Find(int k, T& x) const; int Search(const T& x) const; IndirectList<T>& Delete(int k, T& x); IndirectList<T>& Insert(int k, const T& x); void Output(ostream& out) const;private: T **table; //一维T类型指针数组 int length, MaxSize;};template<class T>IndirectList<T>::IndirectList(int MaxListSize){ //构造函数 MaxSize = MaxListSize; table = new T *[MaxSize]; length = 0;};template<class T>IndirectList<T>::~IndirectList(){ //删除表 for (int i = 0; i < length; i++) delete table[i]; delete[] table;};template<class T>bool IndirectList<T>::Find(int k, T& x) const{ //取第k个元素至x //如果不存在第k个元素,函数返回false,否则返回true if (k < 1 || k > length) return false; //不存在第k个元素 x = *table[k - 1]; return true;};template<class T>IndirectList<T>& IndirectList<T>::Delete(int k, T& x){ //把第k个元素传送至x,然后删除第k个元素 // 如果不存在第k个元素,则引发异常OutOfBounds if (Find(k, x)) { //向前移动指针k+l, ... for (int i = k; i < length; i++) table[i - l] = table[i]; length--; return *this; } else throw OutOfBounds();};template<class T>IndirectList<T>& IndirectList<T>::Insert(int k, const T& x){ // 在第k个元素之后插入x // 如果不存在第k个元素,则引发异常OutOfBounds // 如果没有足够的空间,则传递NoMem异常 if (k < 0 || k > length) throw OutOfBounds(); if (length == MaxSize) throw NoMem(); // 向后移动一个位置 for (int i = length - 1; i >= k; i--) table[i + 1] = table[i]; table[k] = new T; *table[k] = x; length++; return *this;}
以上内容整理自网络电子资料,仅供学习交流用,勿作商业用途。转载请注明来源。
阅读全文
0 0
- 间接寻址
- 间接寻址
- 间接寻址
- 间接寻址表
- 寄存器间接寻址方式
- 寄存器间接寻址方式
- 汇编语言--寄存器间接寻址
- 数据结构之间接寻址
- 间接寻址Test1
- 间接寻址--简单操作
- 间接寻址实现
- 间接寻址的实现
- 实验二间接寻址
- C++间接寻址实现
- 立即寻址,直接寻址,间接寻址
- C4047、间接级别、间接寻址级别不同
- 经典数据结构之间接寻址
- 间接寻址的自我练习
- python--字符串
- 【iOS】自定义控件之长按按钮
- Python编译目录下的所有文件通过这个命令,可以将指定目录下的所有py文件编译成pyc,包括子目 Python编译目录下的所有
- Top 10 Games on Linux -sudo update
- Mybatis Spring multiple databases Java configuration
- 间接寻址
- 对象池
- linux面试
- POJ 2392
- linux常用命令
- 背包九讲——01背包
- android requestFocus的使用
- 关于内存申请的问题
- java.net.ProtocolException: unexpected end of stream