Diffstat (limited to 'noncore/apps/opie-reader/my_list.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/my_list.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/my_list.h b/noncore/apps/opie-reader/my_list.h index b3f0cc0..f180d3d 100644 --- a/noncore/apps/opie-reader/my_list.h +++ b/noncore/apps/opie-reader/my_list.h @@ -7,81 +7,84 @@ class CList struct node { T data; node* next; node(T _data, node* _next = NULL) : data(_data), next(_next) {} node() : next(NULL) {}; }; protected: node* front; node* back; public: CList() : front(NULL), back(NULL) {} ~CList() { if (front != NULL) { while (front != NULL) { node *p = front; front = p->next; delete p; } } } + T& first() { return front->data; } + T& last() { return back->data; } T* operator[](int n) { node* current = front; while (n-- > 0) { if ((current = current->next) == NULL) return NULL; } return &(current->data); } void push_front(const T& t) { node* n = new node(t,front); if (front == NULL) { front = back = n; } else front = n; } void push_back(const T& t) { node* n = new node(t); if (front == NULL) { front = back = n; } else { back->next = n; back = n; } } + bool isEmpty() { return (front == NULL); } void erase(unsigned int n) { node* p = front; node* last = front; while (n-- > 0) { last = p; p = p->next; if (p == NULL) return; } if (p == front) { front = p->next; } else { last->next = p->next; } if (p == back) { back = last; } delete p; } @@ -134,39 +137,47 @@ class CList } class iterator { node* current; public: iterator(node* _c) : current(_c) {} iterator& operator++() { current = current->next; return *this; } iterator& operator++(int) { current = current->next; return *this; } T operator*() { return current->data; } T* operator->() { return &(current->data); } + T* pContent() + { + return &(current->data); + } bool operator!=(iterator t) { return (current != t.current); } + bool operator==(iterator t) + { + return (current == t.current); + } }; iterator begin() { return iterator(front); } iterator end() { return iterator(NULL); } }; #endif |