-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathList.lua
61 lines (51 loc) · 977 Bytes
/
List.lua
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
local GOW = GuildsOfWow;
local List = {};
local function newList()
return GOW.Class:createObject(List, { first = 0, last = -1 });
end
GOW.Class:createClass("List", List, newList);
function List:push(value)
local last = self.last + 1;
self.last = last;
self[last] = value;
end
function List:isEmpty()
if self.first > self.last then
return true;
else
return false;
end
end
function List:peek()
if self:isEmpty() then return nil end
return self[self.first];
end
function List:pop()
local value = self:peek();
self[self.first] = nil;
self.first = self.first + 1;
return value
end
function List:count()
return self.last + 1;
end
function List:contains(value)
for a = 0, self:count() do
if (self[a] == value) then
return true;
end
end
return false;
end
function List:remove(value)
for a = 0, self:count() do
if (self[a] == value) then
self[a] = nil;
end
end
end
function List:clear()
while not self:isEmpty() do
self:pop();
end
end