The algorithm to implement a double-ended queue ADT of integers using an array.



The algorithm to implement the above problem:

1.  Algorithm for insertion at rear end:
Step 1: check if(front==-1)
front++
rear++
read the element to insert a[rear]
count++;
Step 2: check if(rear>=SIZE-1)
print Insertion is not possible, overflow!!!
return
Step 3: Increment the rear by 1
read the element to insert a[rear]
count++;
Step 4: stop

2.  Algorithm for insertion at front end:
Step 1: check if(front==-1)
front++
rear++
read the element to insert a[rear]
count++
Step 2: check if(rear>=SIZE-1)
print Insertion is not possible, overflow!!!
return
Step 3: Repeat the steps a to d until i>0
a. a[i]=a[i-1]
b. read the element to insert a[i]
c. count++
d. rear++;
Step 4: stop

3.  Algorithm for deletion at rear end:
Step 1: check if (front==-1)
Print Deletion is not possible: Dequeue is empty
return


Step 2: otherwise
Print The deleted element is a[rear]
Check if(front==rear)
front=rear=-1
otherwise
rear=rear-1
Step 3: stop

4.  Algorithm for deletion at front end:
1: check if (front==-1)
Print Deletion is not possible: Dequeue is empty
return
Step 2: otherwise
Print The deleted element is a[front]
Check if(front==rear)
front=rear=-1
otherwise
front=front-1
Step 3: stop

5.  Algorithm for displaying the dequeue:
Step 1: check if (front==-1)
Print Dequeue is empty
return


Step 2: otherwise
Repeat step a until i<=rear (i=front)
Print a[i]
Step 3: stop



Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments:

Thanks
Mukesh Rajput