1 |
Douglas Thrift |
1 |
// Doubly Linked List |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#ifndef _DoublyLinkedList_hpp_ |
8 |
|
|
#define _DoublyLinkedList_hpp_ |
9 |
|
|
|
10 |
|
|
#include "NullNode.hpp" |
11 |
|
|
#include "Iterator.hpp" |
12 |
|
|
|
13 |
|
|
template<typename Type> |
14 |
|
|
class DoublyLinkedList |
15 |
|
|
{ |
16 |
|
|
private: |
17 |
Douglas Thrift |
3 |
NullNode<Type> front; |
18 |
|
|
NullNode<Type> back; |
19 |
Douglas Thrift |
1 |
public: |
20 |
Douglas Thrift |
3 |
DoublyLinkedList() { front.setNext(&back); back.setPrevious(&front); } |
21 |
|
|
~DoublyLinkedList(); |
22 |
Douglas Thrift |
4 |
void addFront(const Type& value) { front.addNext(value); } |
23 |
|
|
void addBack(const Type& value) { back.addPrevious(value); } |
24 |
|
|
bool contains(const Type& value) { return front.contains(value, &back); } |
25 |
Douglas Thrift |
6 |
void removeFirst(const Type& value) { front.remove(value, &back); } |
26 |
|
|
void removeLast(const Type& value) { back.remove(value, &front, false); } |
27 |
Douglas Thrift |
1 |
}; |
28 |
|
|
|
29 |
Douglas Thrift |
3 |
template<typename Type> |
30 |
|
|
DoublyLinkedList<Type>::~DoublyLinkedList() |
31 |
|
|
{ |
32 |
|
|
while (front.getNext() != &back) front.removeNext(); |
33 |
|
|
} |
34 |
|
|
|
35 |
Douglas Thrift |
1 |
#endif // _DoublyLinkedList_hpp_ |