0% found this document useful (0 votes)
1 views3 pages

Deque Python

Uploaded by

kebacog890
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)
1 views3 pages

Deque Python

Uploaded by

kebacog890
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

from array import *

MAX=5

class deque_array:
deque=array('i',[0,0,0,0,0])
rear=-1
front=-1

def insertion_rear_end(self,n):
if ([Link] == MAX - 1):
print("Insertion Not Possible")
else:
[Link] = [Link] + 1
[Link][[Link]] = n
print("One item added")

def insertion_front_end(self,n):
if ([Link] == - 1):
print("Insertion Not Possible")
else:
[Link][[Link]] = n
[Link] = [Link] - 1
print("One item added")

def deletion_front_end(self):
if [Link] == [Link]:
print("Empty deque")
else:
[Link] = [Link] + 1
n = [Link][[Link]]
print("Deleted item=", n)
def deletion_rear_end(self):
if [Link] == [Link]:
print("Empty deque")
else:
n = [Link][[Link]]
[Link] = [Link] - 1
print("Deleted item=", n)

def display(self):
# print([Link])
if [Link] == [Link]:
print("Empty Queue")
else:
print("The deque is given below:")
i = [Link] + 1
while (i <= [Link]):
print([Link][i])
i = i + 1

dq=deque_array()

while True:
print("**** Main Menu **** ")
print("1. INSERTION REAR END")
print("2. INSERTION FRONT END")
print("3. DELETION FRONT END")
print("4. DELETION REAR END")
print("5. DISPLAY")
print("0. EXIT")

ch=int(input("Enter Your Choice:"))


if(ch==1):
n = int(input("Enter data:"))
dq.insertion_rear_end(n)

elif (ch == 2):


n = int(input("Enter data:"))
dq.insertion_front_end(n)

elif (ch == 3):


dq.deletion_front_end()

elif (ch == 4):


dq.deletion_rear_end()

elif(ch==5):
[Link]()

elif (ch == 0):


break

else:
print("Wrong Input")
pass

You might also like