Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
345 views
in RTU/BTU B.Tech(CSE-III Sem) DSA LAB by Goeduhub's Expert (7.6k points)

Implementation of dequeue using a one dimensional array as storage element. The program should implement the basic addition, deletion operations. 

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Ques .Implementation of dequeue using a one dimensional array as storage element. The program should implement the basic addition, deletion operations. 

Answer : 

Dequeue : Dequeue is also known as Double Ended Queue is also a Queue data structure in which the insertion and deletion operations are performed at both the ends (front and rear). That means, we can insert at both front and rear positions and can delete from both front and rear positions.Double Ended Queue can be represented in two ways:

  1. Input Restricted Double Ended Queue - the insertion operation is performed at only one end and deletion operation is performed at both the ends.
  2. Output Restricted Double Ended Queue -  the deletion operation is performed at only one end and insertion operation is performed at both the ends.

Examples :

  1. Ticket counter line where people who come first will get his ticket first.
  2. Bank line where people who come first will done his transaction first.
  3. Toilet or Washroom use line 
  4. All the lines similar like above.
  5. Key press sequence in keyboard.
  6. ATM booth line

Program of de-queue :

#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))

 Output : 

[1]

[1, 2] 

[1, 2, 3] 

[1, 2, 3, 4] 

[1, 2, 3, 4, 5] 

[1, 2, 3, 4] 

[1, 2, 3] 

[6, 1, 2, 3] 

[7, 6, 1, 2, 3] 

[8, 7, 6, 1, 2, 3] 

[7, 6, 1, 2, 3] 

[6, 1, 2, 3] 

3


For more Rajasthan Technical University CSE-III Sem DSA Lab Experiments  CLICK HERE

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory
...