数据结构之线性表栈队列
Posted triw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据结构之线性表栈队列相关的知识,希望对你有一定的参考价值。
温故而知新~~~~
一、线性表
顺序表实现(C++)
1 template<typename E> 2 class AList 3 { 4 private: 5 int maxSize; 6 int listSize; 7 int curr; 8 E* listArray; 9 public: 10 AList(int size = defaultSize) 11 { 12 maxSize = size; 13 listSize = curr = 0; 14 listArray = new E[maxSize]; 15 } 16 ~AList() { delete[] listArray; } 17 void clear() 18 { 19 delete[] listArray; 20 listSize = curr = 0; 21 listArray = new E[maxSize]; 22 } 23 void insert(const E& it) 24 { 25 Assert(listSize < maxSize, "exceed"); 26 for (int i = listSize; i > curr; i--) 27 listArray[i] = listArray[i - 1]; 28 listArray[curr] = it; 29 listSize++; 30 } 31 void append(const &E it) 32 { 33 Assert(listSize < maxSize, "exceeded"); 34 listArray[listSize++] = it; 35 } 36 E remove() 37 { 38 Assert((curr >= 0) && (curr < listSize), "GG"); 39 E it = listArray[curr]; 40 for (int i = curr; curr < listArray - 1; i++) 41 listArray[i] = listArray[i + 1]; 42 listSize--; 43 return it; 44 } 45 void moveToStart() { curr = 0; } 46 void moveToEnd() { curr = listSize; } 47 void prev() { if (curr != 0)curr--; } 48 void next() { if (curr < listSize)curr++; } 49 50 int length()const { return listSize; } 51 int currPos const 52 { 53 return curr; 54 } 55 void moveToPos(int os) 56 { 57 Assert((pos >= 0) && (pos <= listSize), "GG"); 58 curr = pos; 59 } 60 61 const E& getValue() const 62 { 63 Assert((curr >= 0) && (curr < listSize), "GG"); 64 return listArray[curr]; 65 } 66 };
以上是关于数据结构之线性表栈队列的主要内容,如果未能解决你的问题,请参考以下文章