Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Double Ended Queue In C #1692

Closed
wants to merge 1 commit into from

Conversation

DinkyRajpoot56
Copy link

Solved Issue no.#1659

Please merge my pull request..It is working properly....

Aim : Adding Double Ended Queue
Username :
Screenshot (3633)
DinkyRajpoot56
Date: 6/11/2024

Insertion at Front in Deque in C
To insert an element at the front end of the deque first, check if the deque is full or not if deque is not full then follow the below approach:

InsertAtFrontinDeque-(1)
Insert at front in deque
Approach:

First, check the position of the front in our array.
If front < 1 , reinitialize front as the last index of the array i.e. front = N-1.
Then, add new element to array[front].

Insertion at Rear in Deque in C
InsertiAtRearinDeque-(1)
Insert at Rear in Deque
To insert an element at the rear end of the deque, follow the below approach:

Approach:

First, check if the deque is full or not.
If the deque is full , reinitialize rear with 0 (rear = 0) else increase rear by 1.
Then, add the element to array[rear].

Deletion at Front in Deque in C

To delete an element at the front end of the deque first, follow the below approach:

Approach:

First, check if deque is empty or not.
If the deque is empty (front == -1), then we cannot perform deletion operation. In this condition, we will simply print undeflow.
If deque contains only 1 element (front = rear) , then only one deletion operation can be performed. set front = -1 and rear = -1.
Else if the front is at the last index ( front == n-1 ) , set front at starting index of deque (front = 0).
If none of the above case exists, just increment front by 1 (front = front + 1).

Deletion at Rear in Deque in C
DeletionAtRear
Delete at Rear in Deque
To delete an element at the rear end of the deque, follow the below approach:

First, check if the deque is empty or not.
If the deque is empty (front = -1), then deletion operation cannot be performed and we will print underflow.
If the deque has only 1 element( front==rear), we will set front = -1 and rear =-1.
If the rear is at the starting index of deque (rear == 0) , then set rear to last index (rear = n-1).
If none of the above case exists, just decrement rear by 1 (rear = rear-1).

Check if Deque is Empty or Not Empty
To check if the deque is empty simply check the front if front = -1, then deque is empty else it is not empty.

Check if Deque is Full or Not Full
To check if the deque is full simply check the below conditions:

If front == 0 and rear == n-1 , then deque is Full
If front == rear + 1 , then also deque is Full.
Screenshot (3634)
Screenshot (3635)
Screenshot (3636)
Screenshot (3637)
Screenshot (3638)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant