0% found this document useful (0 votes)
2 views1 page

Python Queue Implementation Guide

Uploaded by

mmind6167
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Python Queue Implementation Guide

Uploaded by

mmind6167
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Implement Queue using python

class Queue:
def __init__(self):
[Link] = []

def is_empty(self):
return len([Link]) == 0

def enqueue(self, item):


[Link](item)

def dequeue(self):
if not self.is_empty():
return [Link](0)
else:
raise IndexError("Queue is empty")

def peek(self):
if not self.is_empty():
return [Link][0]
else:
raise IndexError("Queue is empty")

def size(self):
return len([Link])

queue = Queue()

[Link](1)
[Link](2)
[Link](3)

print("Queue:", [Link])
print("Queue size:", [Link]())
print("Front element:", [Link]())

dequeued_item = [Link]()
print("Dequeued item:", dequeued_item)
print("Queue:", [Link])

Output :-
Queue: [1, 2, 3]
Queue size: 3
Front element: 1
Dequeued item: 1
Queue: [2, 3]

You might also like