Exp 4
Exp 4
Software / Language: C
Description:
• FIFO Principle: In a queue, the first element added is the first one to be removed. This is similar to a
queue of people waiting in line; the first person to get in line is the first to be served.
• Basic Operations:
o Peek/Front: Access the element at the front of the queue without removing it.
• Fixed Size: An array-based queue has a fixed size. Once initialized, the size cannot change.
• Circular Queue: To efficiently use the array space and avoid wasting storage, a circular queue can be
implemented. This allows the rear of the queue to wrap around to the front when space is available.
• Data Structures:
o Front: An index pointing to the position of the first element in the queue.
o Rear: An index pointing to the position where the next element will be added.
1. Initialization:
2. Enqueue Operation:
o If not full, place the new element at the position indicated by rear.
3. Dequeue Operation:
o If not empty, remove the element from the position indicated by front.
o Update the front index to the next position (circularly).
4. Peek Operation:
o Return the element at the position indicated by front without changing the front index.
5. IsEmpty Operation:
o Check if size is 0.
6. IsFull Operation:
Conclusion:
• A linear queue is a data structure that follows the First-In-First-Out (FIFO) principle, where the first element
inserted is the first one to be removed.
• Implementing a linear queue using an array provides a straightforward and efficient approach.
• The key operations for a queue include enqueue (insertion), dequeue (removal), and checking if the queue is
empty or full.
• By properly managing the front and rear indices of the array, the queue can be efficiently implemented.
Result: