-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwoWayList.h
79 lines (57 loc) · 1.42 KB
/
TwoWayList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _TWO_WAY_LIST_H
#define _TWO_WAY_LIST_H
template <class Type>
class TwoWayList {
public:
// basic constructor function
TwoWayList ();
// deconstructor function
~TwoWayList ();
// swap operator
void operator &= (TwoWayList & List);
// add to current pointer position
void Insert (Type *Item);
// remove from current position
void Remove (Type *Item);
// get a reference to the current item, plus the offset given
Type* Current (int offset);
// move the current pointer position backward through the list
void Retreat ();
// move the current pointer position forward through the list
void Advance ();
// operations to check the size of both sides
int LeftLength ();
int RightLength ();
// operations to swap the left and right sides of two lists
void SwapLefts (TwoWayList & List);
void SwapRights (TwoWayList & List);
// operations to move the the start of end of a list
void MoveToStart ();
void MoveToFinish ();
TwoWayList (TwoWayList & List);
private:
struct Node {
// data
Type *data;
Node *next;
Node *previous;
// constructor
Node () : data (0), next (0), previous (0) {}
// deconstructor
~Node ()
{
delete data;
}
};
struct Header {
// data
Node * first;
Node * last;
Node * current;
int leftSize;
int rightSize;
};
// the list itself is pointed to by this pointer
Header *list;
};
#endif