KL_02_schusterje/queue.py

45 lines
1.2 KiB
Python
Raw Permalink Normal View History

2025-01-13 20:48:05 +01:00
class Element:
def __init__(self, data, prev, next):
self.data = data
self.prev = prev
self.next = next
class Queue2:
def __init__(self):
self.butt = None
self.head = None
def isEmpty(self):
if self.butt is None and self.head is None:
return True
else:
return False
def showQueue(self):
print(f"QUEUE head: {self.head}, butt: {self.butt}")
current = self.head
while current is not None:
print(f"Data: {current.data}")
current = current.next
print("----")
def enqueue(self, data):
newElement = Element(data, self.butt, None)
self.butt = newElement
if self.head is None:
self.head = newElement
else:
current = self.head
while current.next is not None:
current = current.next
current.next = newElement
def dequeue(self):
if self.head is not None:
2025-01-13 21:14:22 +01:00
ausgabe = self.head
2025-01-13 20:48:05 +01:00
self.head = self.head.next
if self.head is None:
self.butt = None
return ausgabe