0% found this document useful (0 votes)
9 views7 pages

Python Queue Data Structure Code

The document outlines a simple queue implementation using Python, allowing users to add, delete, and display elements in the queue. It includes functions for enqueueing, dequeueing, and displaying the queue's contents, along with a user interface for operation selection. The program handles cases for full and empty queues, providing appropriate messages to the user.

Uploaded by

Kasthuri L
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)
9 views7 pages

Python Queue Data Structure Code

The document outlines a simple queue implementation using Python, allowing users to add, delete, and display elements in the queue. It includes functions for enqueueing, dequeueing, and displaying the queue's contents, along with a user interface for operation selection. The program handles cases for full and empty queues, providing appropriate messages to the user.

Uploaded by

Kasthuri L
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

QUEUE IMPLEMENTATION

q=[]

print("\t\t\t QUEUE IMPLEMENTATION")

print("\t\t\t ********************")

size=int(input("Enter the size of queue:"))

def Enqueue():

if len(q)==size:

print("Queue is full!!!")

else:

element=input("Enter the added element:")

[Link](element)

print(element,"is added to the Queue!")

def dequeue():

if not q:

print("Queue is empty!!!")

else:

e=[Link](0)

print("element removed!!:",e)

def display():

print(q)

while True:

print("select the operation:\[Link] \[Link] \[Link] \[Link]")

choice=int(input("Enter your choice:"))

if choice==1:

Enqueue()
elif choice==2:

dequeue()

elif choice==3:

display()

elif choice==4:

break

else:

print("Invalid operation!!!")
OUTPUT:

QUEUE IMPLEMENTATION

*************************

Enter the size of queue:5

select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:1

Enter the added element:4

4 is added to the Queue!

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:1

Enter the added element:5

5 is added to the Queue!

Select the operation:

[Link]

[Link]

[Link]

[Link]
Enter your choice:1

Enter the added element:3

3 is added to the Queue!

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:1

Enter the added element:9

9 is added to the Queue!

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:1

Enter the added element:2

2 is added to the Queue!

Select the operation:

[Link]

[Link]

[Link]

[Link]
Enter your choice:3

['4', '5', '3', '9', '2']

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:2

element removed!!: 4

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:2

element removed!!: 5

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:2

element removed!!: 3
Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:2

element removed!!: 9

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:3

['2']

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:2

element removed!!: 2
Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:3

[]

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:2

Queue is empty!!!

Select the operation:

[Link]

[Link]

[Link]

[Link]

Enter your choice:4

You might also like