-
Notifications
You must be signed in to change notification settings - Fork 42
/
LinkClass.h
131 lines (99 loc) · 2.32 KB
/
LinkClass.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#pragma once
#include <GeneralDefinitions.h>
//Abstract class for a node in a linked list (not to confuse with GenericNode, which is the same, just templated)
class LinkClass
{
public:
//Destructor
virtual ~LinkClass()
{ JMP_THIS(0x5565A0); }
//LinkClass
virtual LinkClass* GetNext()
{ return Next; }
virtual LinkClass* GetPrevious()
{ return Previous; }
virtual LinkClass* AddBeforeMe(LinkClass* pLink) //adds pLink to the list, one node before this
//returns first node of the list
{
IsolateFromList();
Next = pLink->Next;
Previous = pLink;
pLink->Next = this;
if(Next) {
Next->Previous = this;
}
return GetFirst();
}
virtual LinkClass* PutAtEndOf(LinkClass* pLink) //puts this at the end of the list pLink is in
//returns first node of that list
{
IsolateFromList();
LinkClass* pLast = pLink->GetLast();
pLast->Next = this;
Previous = pLast;
Next = nullptr;
return GetFirst();
}
virtual LinkClass* PutAtBeginningOf(LinkClass* pLink) //puts this at the beginning of the list pLink is in
//returns first node of that list (this)
{
IsolateFromList();
LinkClass* pFirst = pLink->GetFirst();
pFirst->Previous = this;
Next = pFirst;
Previous = nullptr;
return this;
}
virtual LinkClass* GetFirst() //finds the first node in the list
{
LinkClass* p = this;
while(p->Previous) {
p = p->Previous;
if(p == this) {
return this;
}
}
return p;
}
virtual LinkClass* GetLast() //finds the last node in the list
{
LinkClass* p = this;
while(p->Next) {
p = p->Next;
if(p == this) {
return this;
}
}
return p;
}
virtual void Isolate() //removes this from the list
{
Next = nullptr;
Previous = nullptr;
}
virtual LinkClass* IsolateFromList() //removes this from the list
//returns first node if possible
{
LinkClass* pFirst = GetFirst();
LinkClass* pLast = GetLast();
if(Next) {
Next->Previous = Previous;
}
if(Previous) {
Previous->Next = Next;
}
Previous = nullptr;
Next = nullptr;
if(pFirst != this) {
return pFirst;
} else if(pLast && pLast != this) {
return pLast->GetFirst();
} else {
return nullptr;
}
}
//Properties
public:
LinkClass* Next;
LinkClass* Previous;
};