author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (unidiff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/my_list.h | |
parent | e90847c784c48bd21bf8768cb38edb853b832697 (diff) | |
download | opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2 |
updated source to opie-reader 0.7g
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.h | 12 |
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 @@ | |||
1 | #ifndef __MY_LIST_H | 1 | #ifndef __MY_LIST_H |
2 | #define __MY_LIST_H | 2 | #define __MY_LIST_H |
3 | 3 | ||
4 | #ifndef NULL | ||
5 | #define NULL 0 | ||
6 | #endif | ||
7 | |||
4 | template<class T> | 8 | template<class T> |
5 | class CList | 9 | class CList |
6 | { | 10 | { |
7 | struct node | 11 | struct node |
8 | { | 12 | { |
9 | T data; | 13 | T data; |
10 | node* next; | 14 | node* next; |
11 | node(T _data, node* _next = NULL) : data(_data), next(_next) {} | 15 | node(T _data, node* _next = NULL) : data(_data), next(_next) {} |
12 | node() : next(NULL) {}; | 16 | node() : next(NULL) {}; |
13 | }; | 17 | }; |
14 | protected: | 18 | protected: |
15 | node* front; | 19 | node* front; |
@@ -21,24 +25,32 @@ class CList | |||
21 | if (front != NULL) | 25 | if (front != NULL) |
22 | { | 26 | { |
23 | while (front != NULL) | 27 | while (front != NULL) |
24 | { | 28 | { |
25 | node *p = front; | 29 | node *p = front; |
26 | front = p->next; | 30 | front = p->next; |
27 | delete p; | 31 | delete p; |
28 | } | 32 | } |
29 | } | 33 | } |
30 | } | 34 | } |
31 | T& first() { return front->data; } | 35 | T& first() { return front->data; } |
32 | T& last() { return back->data; } | 36 | T& last() { return back->data; } |
37 | T pop() | ||
38 | { | ||
39 | T data = front->data; | ||
40 | node* n = front; | ||
41 | front = front->next; | ||
42 | delete n; | ||
43 | return data; | ||
44 | } | ||
33 | T* operator[](int n) | 45 | T* operator[](int n) |
34 | { | 46 | { |
35 | node* current = front; | 47 | node* current = front; |
36 | while (n-- > 0) | 48 | while (n-- > 0) |
37 | { | 49 | { |
38 | if ((current = current->next) == NULL) | 50 | if ((current = current->next) == NULL) |
39 | return NULL; | 51 | return NULL; |
40 | } | 52 | } |
41 | return &(current->data); | 53 | return &(current->data); |
42 | } | 54 | } |
43 | void push_front(const T& t) | 55 | void push_front(const T& t) |
44 | { | 56 | { |