In [1]:
#Queue with Integers
class IntegerQueue:
def __init__(self):
self.queue = []
def push(self, item: int):
self.queue.append(item)
def pop(self):
if not self.is_empty():
return self.queue.pop(0)
return None
def is_empty(self):
return len(self.queue) == 0
def __str__(self):
return f"IntegerQueue({self.queue})"
def __repr__(self):
return self.__str__()
int_queue = IntegerQueue()
int_queue.push(1)
int_queue.push(2)
print(int_queue)
print(int_queue.pop())
print(int_queue)
IntegerQueue([1, 2]) 1 IntegerQueue([2])
In [2]:
#Queue with Strings
class StringQueue:
def __init__(self):
self.queue = []
def push(self, item: str):
self.queue.append(item)
def pop(self):
if not self.is_empty():
return self.queue.pop(0)
return None
def is_empty(self):
return len(self.queue) == 0
def __str__(self):
return f"StringQueue({self.queue})"
def __repr__(self):
return self.__str__()
str_queue = StringQueue()
str_queue.push("hello")
str_queue.push("world")
print(str_queue)
print(str_queue.pop())
print(str_queue)
StringQueue([''''hello'''', ''''world'''']) hello StringQueue([''''world''''])
In [3]:
import pprint
#Queue with Dictionaries (Healthcare Data)
class HealthcareQueue:
def __init__(self):
self.queue = []
def push(self, item: dict):
self.queue.append(item)
def pop(self):
if not self.is_empty():
return self.queue.pop(0)
return None
def is_empty(self):
return len(self.queue) == 0
def __str__(self):
return f"HealthcareQueue({self.queue})"
def __repr__(self):
return self.__str__()
health_queue = HealthcareQueue()
health_queue.push({"patient_id": 1, "name": "John Doe", "condition": "Flu"})
health_queue.push({"patient_id": 2, "name": "Jane Doe", "condition": "Cold"})
pprint.pp(health_queue)
pprint.pp(health_queue.pop())
pprint.pp(health_queue)
HealthcareQueue([{''''patient_id'''': 1, ''''name'''': ''''John Doe'''', ''''condition'''': ''''Flu''''}, {''''patient_id'''': 2, ''''name'''': ''''Jane Doe'''', ''''condition'''': ''''Cold''''}]) {''''patient_id'''': 1, ''''name'''': ''''John Doe'''', ''''condition'''': ''''Flu''''} HealthcareQueue([{''''patient_id'''': 2, ''''name'''': ''''Jane Doe'''', ''''condition'''': ''''Cold''''}])
In [4]:
#Generic Queue
class GenericQueue:
def __init__(self):
self.queue = []
def push(self, item):
self.queue.append(item)
def pop(self):
if not self.is_empty():
return self.queue.pop(0)
return None
def is_empty(self):
return len(self.queue) == 0
def __str__(self):
return f"GenericQueue({self.queue})"
def __repr__(self):
return self.__str__()
gen_queue = GenericQueue()
gen_queue.push(1)
gen_queue.push("hello")
gen_queue.push({"key": "value"})
print(gen_queue)
print(gen_queue.pop())
print(gen_queue)
GenericQueue([1, ''''hello'''', {''''key'''': ''''value''''}]) 1 GenericQueue([''''hello'''', {''''key'''': ''''value''''}])