-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.py
44 lines (30 loc) · 1.21 KB
/
Queue.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
from typing import Optional
from DoublyLinkedList import DoublyLinkedList
class Queue(object):
def __init__(self, initialItems: list[object]) -> None:
self.queue: DoublyLinkedList = DoublyLinkedList(initialItems)
def enqueue(self, value: object) -> None:
return self.queue.insertAtTail(value)
def dequeue(self) -> Optional[object]:
return self.queue.removeFromHead()
def peek(self) -> Optional[object]:
return self.queue.getHead()
def size(self) -> int:
return self.queue.getLength()
class DeQueue(object):
def __init__(self, initialItems: list[object]) -> None:
self.queue: DoublyLinkedList = DoublyLinkedList(initialItems)
def pushLeft(self, value: object) -> None:
self.queue.insertAtHead(value)
return
def popleft(self) -> Optional[object]:
return self.queue.removeFromHead()
def peek(self) -> Optional[object]:
return self.queue.getHead()
def size(self) -> int:
return self.queue.getLength()
def pushRight(self, value: object) -> None:
self.queue.insertAtTail(value)
return
def popRight(self, value: object) -> Optional[object]:
return self.queue.removeFromTail()