X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=stl-model.h;h=53e412061d2178fc3f839882fa883400c57b4944;hb=HEAD;hp=74aaee698f0d9a05e74b030cf0e4cb285bc2fe12;hpb=66a81d85cc79168151a315b33ba9500c12d199d7;p=c11tester.git diff --git a/stl-model.h b/stl-model.h index 74aaee69..53e41206 100644 --- a/stl-model.h +++ b/stl-model.h @@ -5,7 +5,6 @@ #include "mymemory.h" typedef unsigned int uint; - template class mllnode { public: @@ -60,9 +59,9 @@ public: mllnode<_Tp> *tmp = head; head = head->next; if (head == NULL) - tail = NULL; + tail = NULL; else - head->prev = NULL; + head->prev = NULL; delete tmp; _size--; } @@ -71,9 +70,9 @@ public: mllnode<_Tp> *tmp = tail; tail = tail->prev; if (tail == NULL) - head = NULL; + head = NULL; else - tail->next = NULL; + tail->next = NULL; delete tmp; _size--; } @@ -126,7 +125,7 @@ public: if (tail == node) { tail = node->prev; } else { - tail->next->prev = node->prev; + node->next->prev = node->prev; } mllnode<_Tp> *next = node->next; delete node; @@ -165,6 +164,8 @@ private: uint _size; }; +class actionlist; + template class sllnode { public: @@ -179,6 +180,7 @@ private: _Tp val; template friend class SnapList; + friend class actionlist; }; template @@ -214,13 +216,40 @@ public: _size++; } + sllnode<_Tp>* add_front(_Tp val) { + sllnode<_Tp> * tmp = new sllnode<_Tp>(); + tmp->prev = NULL; + tmp->next = head; + tmp->val = val; + if (head == NULL) + tail = tmp; + else + head->prev = tmp; + head = tmp; + _size++; + return tmp; + } + + sllnode<_Tp> * add_back(_Tp val) { + sllnode<_Tp> * tmp = new sllnode<_Tp>(); + tmp->prev = tail; + tmp->next = NULL; + tmp->val = val; + if (tail == NULL) + head = tmp; + else tail->next = tmp; + tail = tmp; + _size++; + return tmp; + } + void pop_front() { sllnode<_Tp> *tmp = head; head = head->next; if (head == NULL) - tail = NULL; + tail = NULL; else - head->prev = NULL; + head->prev = NULL; delete tmp; _size--; } @@ -229,9 +258,9 @@ public: sllnode<_Tp> *tmp = tail; tail = tail->prev; if (tail == NULL) - head = NULL; + head = NULL; else - tail->next = NULL; + tail->next = NULL; delete tmp; _size--; } @@ -246,7 +275,7 @@ public: _size=0; } - void insertAfter(sllnode<_Tp> * node, _Tp val) { + sllnode<_Tp> * insertAfter(sllnode<_Tp> * node, _Tp val) { sllnode<_Tp> *tmp = new sllnode<_Tp>(); tmp->val = val; tmp->prev = node; @@ -258,6 +287,7 @@ public: tmp->next->prev = tmp; } _size++; + return tmp; } void insertBefore(sllnode<_Tp> * node, _Tp val) { @@ -284,7 +314,7 @@ public: if (tail == node) { tail = node->prev; } else { - tail->next->prev = node->prev; + node->next->prev = node->prev; } sllnode<_Tp> *next = node->next; @@ -339,14 +369,14 @@ public: _size(_capacity), capacity(_capacity), array((type *) model_malloc(sizeof(type) * _capacity)) { - memcpy(array, _array, capacity * sizeof(type)); + real_memcpy(array, _array, capacity * sizeof(type)); } void pop_back() { _size--; } type back() const { - return array[size - 1]; + return array[_size - 1]; } void resize(uint psize) { @@ -444,7 +474,7 @@ public: _size(_capacity), capacity(_capacity), array((type *) snapshot_malloc(sizeof(type) * _capacity)) { - memcpy(array, _array, capacity * sizeof(type)); + real_memcpy(array, _array, capacity * sizeof(type)); } void pop_back() { _size--; @@ -509,6 +539,15 @@ public: array[index] = item; } + void remove(type item) { + for(uint i = 0;i < _size;i++) { + if (at(i) == item) { + removeAt(i); + return; + } + } + } + void removeAt(uint index) { for (uint i = index;(i + 1) < _size;i++) { set(i, at(i + 1));