标签:vat type rem 结构 max assert exce for temp
温故而知新~~~~
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 };
标签:vat type rem 结构 max assert exce for temp
原文地址:https://www.cnblogs.com/Triw/p/10105515.html