forked from algorithm-archivists/algorithm-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.py
45 lines (28 loc) · 827 Bytes
/
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
45
#!/usr/bin/env python3
__author__ = "Michael Ciccotosto-Camp"
from typing import TypeVar, Generic
T = TypeVar("T")
class Queue(Generic[T]):
def __init__(self) -> None:
self.__list: list[T] = list()
def dequeue(self) -> T:
return self.__list.pop(0)
def enqueue(self, element: T) -> int:
self.__list.append(element)
return len(self)
def front(self) -> T:
return self.__list[0]
def __len__(self) -> int:
return len(self.__list)
def __str__(self) -> str:
return str(self.__list)
def main() -> None:
int_queue: Queue[int] = Queue()
int_queue.enqueue(4)
int_queue.enqueue(5)
int_queue.enqueue(9)
print(int_queue.dequeue())
print(len(int_queue))
print(int_queue.front())
if __name__ == "__main__":
main()