summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/my_list.h
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-reader/my_list.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/my_list.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/my_list.h b/noncore/apps/opie-reader/my_list.h
index f180d3d..52e6472 100644
--- a/noncore/apps/opie-reader/my_list.h
+++ b/noncore/apps/opie-reader/my_list.h
@@ -1,15 +1,19 @@
#ifndef __MY_LIST_H
#define __MY_LIST_H
+#ifndef NULL
+#define NULL 0
+#endif
+
template<class T>
class CList
{
struct node
{
T data;
node* next;
node(T _data, node* _next = NULL) : data(_data), next(_next) {}
node() : next(NULL) {};
};
protected:
node* front;
@@ -21,24 +25,32 @@ class 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 pop()
+ {
+ T data = front->data;
+ node* n = front;
+ front = front->next;
+ delete n;
+ return 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)
{