X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=stl-model.h;h=cbcae7c04162f979cebb3d338cced3ad5d97e15e;hp=489939b739c97878a7a264b4af3d0cc08caf3e3a;hb=51ee3f71895aafae7e7292174862b3ad42c801a6;hpb=8033d9604aedac4430797fcc414d8880f7eb967f diff --git a/stl-model.h b/stl-model.h index 489939b7..cbcae7c0 100644 --- a/stl-model.h +++ b/stl-model.h @@ -59,15 +59,21 @@ public: void pop_front() { mllnode<_Tp> *tmp = head; head = head->next; - head->prev = NULL; + if (head == NULL) + tail = NULL; + else + head->prev = NULL; delete tmp; _size--; } void pop_back() { mllnode<_Tp> *tmp = tail; - tail = tail->next; - tail->next = NULL; + tail = tail->prev; + if (tail == NULL) + head = NULL; + else + tail->next = NULL; delete tmp; _size--; } @@ -120,7 +126,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; @@ -211,15 +217,21 @@ public: void pop_front() { sllnode<_Tp> *tmp = head; head = head->next; - head->prev = NULL; + if (head == NULL) + tail = NULL; + else + head->prev = NULL; delete tmp; _size--; } void pop_back() { sllnode<_Tp> *tmp = tail; - tail = tail->next; - tail->next = NULL; + tail = tail->prev; + if (tail == NULL) + head = NULL; + else + tail->next = NULL; delete tmp; _size--; } @@ -272,7 +284,7 @@ public: if (tail == node) { tail = node->prev; } else { - tail->next->prev = node->prev; + node->next->prev = node->prev; } sllnode<_Tp> *next = node->next; @@ -334,7 +346,7 @@ public: } type back() const { - return array[size - 1]; + return array[_size - 1]; } void resize(uint psize) { @@ -358,11 +370,11 @@ public: array[_size++] = item; } - type operator[](uint index) const { + type operator[](int index) const { return array[index]; } - type & operator[](uint index) { + type & operator[](int index) { return array[index]; } @@ -463,11 +475,11 @@ public: array[_size++] = item; } - type & operator[](uint index) { + type operator[](int index) const { return array[index]; } - type operator[](uint index) const { + type & operator[](int index) { return array[index]; }