0% found this document useful (0 votes)
20 views2 pages

Exp 4

Uploaded by

Ansh Dabholkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Exp 4

Uploaded by

Ansh Dabholkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT NO 04

AIM: Write a C Program to Implement Linear Queue ADT using array.

Software / Language: C

Description:

1. Concept of a Linear Queue

• 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 Enqueue: Add an element to the rear of the queue.

o Dequeue: Remove an element from the front of the queue.

o Peek/Front: Access the element at the front of the queue without removing it.

o IsEmpty: Check if the queue is empty.

o IsFull: Check if the queue is full (if applicable).

2. Array Representation of Queue

• 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.

3. Queue Implementation Details

• Data Structures:

o Array: Stores the queue elements.

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.

o Size: Keeps track of the number of elements currently in the queue.

4. Operations on Linear Queue

1. Initialization:

o Create an array of fixed size to store queue elements.

o Initialize front and rear indices, and size.

2. Enqueue Operation:

o Check if the queue is full.

o If not full, place the new element at the position indicated by rear.

o Update the rear index to the next position (circularly).

3. Dequeue Operation:

o Check if the queue is empty.

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:

o Check if size is equal to the array’s capacity.

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:

• Enqueue elements: Insert new elements at the rear of the queue.

• Dequeue elements: Remove elements from the front of the queue.

• Check for emptiness: Determine if the queue is empty.

• Check for fullness: Determine if the queue is full.

You might also like