-
Notifications
You must be signed in to change notification settings - Fork 4
/
ds2.py
64 lines (47 loc) · 1.21 KB
/
ds2.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
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
58
59
60
61
62
63
from ds import DoubleLinkedList
class Stack:
def __init__(self):
self.__list = DoubleLinkedList()
def push(self, val):
self.__list.add(val)
def pop(self):
val = self.__list.back()
self.__list.remove_last()
return val
def is_empty(self):
return self.__list.size == 0
def peek(self):
return self.__list.back()
def __len__(self):
return self.__list.size
class Queue:
def __init__(self):
self.__list = DoubleLinkedList()
def enqueue(self, val):
self.__list.add(val)
def deque(self):
val = self.__list.front()
self.__list.remove_first()
return val
def front(self):
return self.__list.front()
def is_empty(self):
return self.__list.size == 0
def __len__(self):
return self.__list.size
# from collections import deque
#
# my_queue = Queue()
# my_queue.enqueue(1)
# print(len(my_queue))
# print(my_queue.front())
# my_queue.enqueue(1)
# my_queue.enqueue(4)
# my_queue.enqueue(10)
# my_queue.enqueue(111)
# print(my_queue.front())
# print(len(my_queue))
# print(my_queue.deque())
# print(my_queue.front())
# my_queue.deque()
# print(my_queue.front())