-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
38 lines (29 loc) · 786 Bytes
/
stack.py
File metadata and controls
38 lines (29 loc) · 786 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
36
37
38
from linked_list import DoubleLinkedList
class Stack:
def __init__(self):
# self.__internal_list = []
self.__list = DoubleLinkedList()
def push(self, value):
# self.__internal_list.append(value)
self.__list.add(value)
def pop(self):
value = self.__list.back()
self.__list.remove_last()
return value
def is_empty(self):
return self.__list.size == 0
def peek(self):
return self.__list.back()
def __len__(self):
# return len(self.__internal_list)
return self.__list.size
my_stack = Stack()
my_stack.push(1)
my_stack.push(2)
my_stack.push(3)
print(my_stack.peek())
my_stack.push(5)
print(len(my_stack))
print(my_stack.pop())
print(len(my_stack))
print(my_stack.peek())