-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassePilha.py
More file actions
35 lines (28 loc) · 889 Bytes
/
ClassePilha.py
File metadata and controls
35 lines (28 loc) · 889 Bytes
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
class Pilha:
def __init__(self, tam_max):
self.elem = [None] * tam_max
self.topo = -1
self.tam_max = tam_max
def InicializaPilha(self):
self.topo = -1
def PilhaVazia(self):
return self.topo == -1
def PilhaCheia(self):
return self.topo == self.tam_max - 1
def ElementoDoTopo(self):
if not self.PilhaVazia():
return self.elem[self.topo]
def Empilha(self, x):
if not self.PilhaCheia():
self.topo += 1
self.elem[self.topo] = x
def Desempilha(self):
if not self.PilhaVazia():
x = self.elem[self.topo]
self.elem[self.topo] = None
self.topo -= 1
if self.PilhaVazia():
self.InicializaPilha()
return x
def mostrar_elementos(self):
return self.elem