📌 Queues: Operations on Queue
A Queue is a linear data structure that follows the FIFO (First-In, First-Out) principle. This means that the element added first will be removed first, just like a queue of people waiting in line.
1️⃣ Basic Queue Operations
Operation | Description |
---|---|
Enqueue() | Adds an element to the rear (back) of the queue. |
Dequeue() | Removes an element from the front of the queue. |
Front() / Peek() | Returns the front element without removing it. |
isEmpty() | Checks if the queue is empty. |
isFull() | Checks if the queue is full (for fixed-size queues). |
2️⃣ Implementation of Queue in C
(a) Queue Using Arrays
✅ Simple Implementation
❌ Wastes space when elements are dequeued (fixed front).
(b) Queue Using Linked List
✅ Efficient memory usage
✅ No fixed size limit
❌ More complex (pointers needed)
3️⃣ Special Types of Queues
1️⃣ Circular Queue – Overcomes the issue of wasted space in arrays.
2️⃣ Deque (Double-Ended Queue) – Can add/remove from both front & rear.
3️⃣ Priority Queue – Elements are dequeued based on priority, not order.
No comments:
Post a Comment