#include "mymemory.h"
typedef unsigned int uint;
-
template<typename _Tp>
class mllnode {
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--;
}
mllnode<_Tp> *tmp = tail;
tail = tail->prev;
if (tail == NULL)
- head = NULL;
+ head = NULL;
else
- tail->next = NULL;
+ tail->next = NULL;
delete tmp;
_size--;
}
if (tail == node) {
tail = node->prev;
} else {
- tail->next->prev = node->prev;
+ node->next->prev = node->prev;
}
mllnode<_Tp> *next = node->next;
delete node;
uint _size;
};
+class actionlist;
+
template<typename _Tp>
class sllnode {
public:
_Tp val;
template<typename T>
friend class SnapList;
+ friend class actionlist;
};
template<typename _Tp>
_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--;
}
sllnode<_Tp> *tmp = tail;
tail = tail->prev;
if (tail == NULL)
- head = NULL;
+ head = NULL;
else
- tail->next = NULL;
+ tail->next = NULL;
delete tmp;
_size--;
}
_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;
tmp->next->prev = tmp;
}
_size++;
+ return tmp;
}
void insertBefore(sllnode<_Tp> * node, _Tp val) {
if (tail == node) {
tail = node->prev;
} else {
- tail->next->prev = node->prev;
+ node->next->prev = node->prev;
}
sllnode<_Tp> *next = node->next;
_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) {
_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--;
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));