1
1
class Node :
2
- """Representação de um nó em Python3. Com ele é possível criar uma pilha encadeada """
2
+ """Class to represent a node in Python3 """
3
3
4
4
def __init__ (self , data ):
5
- self .data = data # Valor do nó
6
- self .next = None # Próximo nó
5
+ self .data = data # Node value
6
+ self .next = None # Next node
7
7
8
8
9
9
class LinkedStack :
10
- """Representação de uma pilha dinâmica encadeada em Python3"""
10
+ """Class to represent a linked stack in Python3"""
11
11
12
12
def __init__ (self ):
13
- self ._top = None # Define o topo da pilha
14
- self ._size = 0 # Tamanho atual da pilha
13
+ self ._top = None # Top of stack
14
+ self ._size = 0 # The stack size
15
15
16
16
def push (self , elem ):
17
- """Insere um elemento no topo da pilha """
17
+ """Adds an element at the top of a stack """
18
18
if self ._size == 0 :
19
19
self ._top = Node (elem )
20
20
else :
@@ -24,35 +24,35 @@ def push(self, elem):
24
24
self ._size += 1
25
25
26
26
def pop (self ):
27
- """Deleta um item do topo da pilha e retorna o seu valor """
27
+ """Removes the topmost element of a stack """
28
28
if self ._size == 0 :
29
- raise Exception ("Pilha vazia " )
29
+ raise Exception ("Empty stack " )
30
30
elem , self ._top = self ._top .data , self ._top .next
31
31
self ._size -= 1
32
32
return elem
33
33
34
34
def top (self ):
35
- """retorna o elemento no topo da pilha """
35
+ """Returns the element on the top of the stack but does not remove it """
36
36
if self ._size == 0 :
37
- raise Exception ("Pilha vazia " )
37
+ raise Exception ("Empty stack " )
38
38
return self ._top .data
39
39
40
40
def empty (self ):
41
- """Verifica se a pilha está vazia """
41
+ """Returns true if the stack is empty, otherwise, it returns false """
42
42
if self ._size == 0 :
43
43
return True
44
44
return False
45
45
46
46
def length (self ):
47
- """Retorna o tamanho da pilha """
47
+ """Returns the size of stack """
48
48
return self ._size
49
49
50
50
def __del__ (self ):
51
- """Método destrutor invocado sempre que o código é finalizado """
51
+ """Destructor method """
52
52
53
53
def __str__ (self ):
54
- """Representa a pilha excluindo os obj NoneType"""
55
- rep = "\033 [1;34m" + "topo -> " + "\033 [0;0m"
54
+ """Method for representing the stack, excluding NoneType objects (user) """
55
+ rep = "\033 [1;34m" + "top -> " + "\033 [0;0m"
56
56
if self ._size == 0 :
57
57
rep += "None"
58
58
return rep
@@ -66,4 +66,5 @@ def __str__(self):
66
66
return rep
67
67
68
68
def __repr__ (self ):
69
+ """Method for representing the stack, excluding NoneType objects (developer)"""
69
70
return str (self )
0 commit comments