Write a C Program to implement Deque using circular array. Queue is also an abstract data type or a linear data structure, in which the first element is inserted from one end called REAR , and the deletion of existing element takes place from the other end called as FRONT.
This makes queue as FIFO data structure, which means that element inserted first will also be removed first. Shift front to the end Else, decrease front by 1. Add the new key 5 into array[front]. Insert the element at Front 2. Insert at the Rear This operation adds an element to the rear. Check if the array is full. Else, increase rear by 1.
Increase the rear Add the new key 5 into array[rear]. Insert the element at rear 3. Delete from the Front. Previous Tutorial:. Next Tutorial:. Previous Deque Set 1 Introduction and Applications. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment?
Please use ide. Load Comments. What's New. Most popular in Queue. More related articles in Queue. We use cookies to ensure you have the best browsing experience on our website. It can be used to implement both conventional stack and queue because of its property of insertion and deletion from both ends.
In the real world it is used to implement A-steal job scheduling algorithm. In the below code we have four prominent functions. We have 3 cases here:. Case 1 : If the array is empty, then we insert the element in the start i.
Case 2 : If the front pointer is at first location i. Case 3 : If the above two cases are not true, then we simply decrement the front pointer and insert the. Case 2 : If the rear pointer is at last location i.
0コメント