forked from tomieiro/std-moon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfila.lua
More file actions
57 lines (48 loc) · 1.42 KB
/
Copy pathfila.lua
File metadata and controls
57 lines (48 loc) · 1.42 KB
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
--Definicao padrao dos atributos da Fila
Fila = {itens = {}, tamanho = 0, _indexfirst = 1, _indexlast = 1};
--Metodo cosntrutor que instancia o objeto Fila.
--args: (Table) Atributos desejados para a Fila.
--return: (Object) Fila instanciada.
function Fila:new(atributos)
atributos = atributos or {};
setmetatable(atributos, self);
self.__index = self;
return atributos;
end
--Metodo push que insere um objeto na Fila.
--args: (Object) Objeto desejados para incluir na Fila.
function Fila:push(objeto)
table.insert(self.itens,self._indexlast,objeto);
self.tamanho = self.tamanho + 1;
self._indexlast = self._indexlast + 1;
return;
end
--Metodo pop que remove um objeto da Fila.
--return: (Object) Objeto removida da Fila.
function Fila:pop()
self._indexfirst = self._indexfirst + 1;
local aux = self.itens[self._indexfirst - 1];
self.itens[self._indexfirst - 1] = nil;
self.tamanho = self.tamanho - 1;
collectgarbage();
return aux;
end
--Funcao que printa toda a lista
function Fila:print()
for i=self._indexfirst, self._indexlast - 1 do
print(self.itens[i])
end
return;
end
--Metodo para liberar a Fila
function Fila:free()
for i=self._indexfirst, self._indexlast - 1 do
self.itens[i] = nil;
end
local aux = {__mode = "k"}
setmetatable(self.itens,aux);
setmetatable(self, aux);
self = nil;
collectgarbage();
end
return Fila;