This repository contains a Java implementation of a Queue using an array, demonstrating circular queue behavior and basic queue operations.
The Queue follows the FIFO (First In, First Out) principle. This implementation uses an array with a circular approach, meaning that when the rear index reaches the end of the array, it wraps around to the beginning if there is space available.
- Enqueue: Inserts an element at the rear of the queue.
- Dequeue: Removes an element from the front of the queue.
- Peek: Retrieves the front element without removing it.
- isEmpty & isFull: Checks if the queue is empty or full.
- Circular Array: Uses modulus arithmetic to wrap indices.
Queue-Activity-Java/
├── src/
│ ├── Queue.java
│ └── Main.java
├── README.html
└── .gitignore
Clone the repository, compile the Java source files, and run the Main class:
git clone https://github.com/Chisa-sifiso/Queue-Activity-Java.git
cd Queue-Activity-Java/src
javac Main.java
java Main
Queue queue = new Queue(5);
queue.enqueue(10);
queue.enqueue(20);
queue.enqueue(30);
queue.printQueue(); // Output: Queue: 10 20 30
System.out.println("Dequeued: " + queue.dequeue());
queue.printQueue();
This project is licensed under the MIT License.
#