-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPilha.py
31 lines (25 loc) · 803 Bytes
/
Pilha.py
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
class Pilha:
def __init__(self, tamanho):
self.tamanho = tamanho
self.cidades = [None] * self.tamanho
self.topo = -1
def empilhar(self, cidade):
if not Pilha.pilhaCheia(self):
self.topo += 1
self.cidades[self.topo] = cidade
else:
print("Pilha esta cheia")
def desempilhar(self):
if not Pilha.pilhaVazia(self):
temporario = self.cidades[self.topo]
self.topo -= 1
return temporario
else:
print("Pilha esta vazia")
return None
def getTopo(self):
return self.cidades[self.topo]
def pilhaVazia(self):
return (self.topo == -1)
def pilhaCheia(self):
return (self.topo == self.tamanho -1)