#creating a deque
def make_dqueue():
dqueue=[]
return dqueue
def dequeue_is_empty(dqueue): #when a dequeue is empty its size is 0
return len(dqueue)==0
def enqueue_rear(dqueue,item):# adding element from last
dqueue.append(item)
def enqueue_front(dqueue,item):#adding element from front
dqueue.insert(0,item)
def dequeue_rear(dqueue):#deleting element from last
dqueue.pop(-1)
def dequeue_front(dqueue):#deleting element from front
dqueue.pop(0)
def last_element(dqueue):#give the peek element
if (queue_is_Empty(dqueue)):
return str(-maxsize -1)
return dqueue[len(dqueue) - 1]
dqueue = make_dqueue()
#adding of element from rear
enqueue_rear(dqueue,1)
print(dqueue)
#adding of element from rear
enqueue_rear(dqueue,2)
print(dqueue)
#adding of element from rear
enqueue_rear(dqueue,3)
print(dqueue)
#adding of element from rear
enqueue_rear(dqueue,4)
print(dqueue)
#adding of element from rear
enqueue_rear(dqueue,5)
print(dqueue)
#removal of element from rear
dequeue_rear(dqueue)
print(dqueue)
#removal of element from rear
dequeue_rear(dqueue)
print(dqueue)
#adding of element from front
enqueue_front(dqueue,6)
print(dqueue)
#adding of element from front
enqueue_front(dqueue,7)
print(dqueue)
#adding of element from front
enqueue_front(dqueue,8)
print(dqueue)
#removing element from front
dequeue_front(dqueue)
print(dqueue)
#removing element from front
dequeue_front(dqueue)
print(dqueue)
#printing peek element of dequeue
print(last_element(dqueue))
|