Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Circular Queue - Java

Description

This program implements a Circular Queue using an array in Java. A circular queue connects the last position of the array back to the first position, allowing unused spaces to be reused.

Features

  • Enqueue operation
  • Dequeue operation
  • Peek operation
  • Display queue elements
  • Reuses empty positions
  • Handles full and empty conditions
  • Menu-driven program

Principle

A Circular Queue follows the FIFO (First In, First Out) principle.

How It Works

The rear moves forward using the modulo operator:

(rear + 1) % queue.length

When the rear reaches the last position, it moves back to the beginning of the array.

Algorithm

  1. Create an array for the queue.
  2. Initialize front and rear to -1.
  3. Insert elements using Enqueue.
  4. Move rear circularly using modulo.
  5. Remove elements using Dequeue.
  6. Move front circularly after deletion.
  7. Display elements from front to rear.
  8. Check whether the queue is full or empty.

Concepts Used

  • Java
  • Arrays
  • Queue
  • Circular Queue
  • FIFO
  • Modulo operator
  • Methods
  • Switch statement

Time Complexity

Enqueue: O(1)

Dequeue: O(1)

Peek: O(1)

Display: O(n)

Space Complexity

O(n)

Sample Output

10 inserted into queue.

20 inserted into queue.

30 inserted into queue.

Queue elements:

10 20 30

10 removed from queue.

40 inserted into queue.

Front element: 20

How to Run

Compile:

javac CircularQueue.java

Run:

java CircularQueue

Learning Outcome

This program helps in understanding circular queues, FIFO operations, array implementation and efficient use of available queue space.

Author

T.Nandhini

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages