- [x] get queue to properly dequeue
- [x] display proper number of elements left in the queue
- [x] make sure program is unbreakable
- [x] extra feature for queue
- [x] allow the user to dequeue or enqueue whenever they want
- [x] fixing remove operation for nodes that are at the end of the list
- [x] determine the book that appears first alphabetically
- [x] determine the book that was published most recently
- [x] allow user to remove or add books as they like
- [x] sorting the nodes
package DataStructures;
public class Queue {
private int[] data; // array to store queue elements
private int front; // front points to the front element in the queue
private int rear; // rear points to the last element in the queue
private int max; // maximum capacity of the queue
private int count; // current size of the queue
public Queue(int maxSize) {
data = new int[maxSize];
max = maxSize;
front = -1;
rear = -1;
count = 0;
}
// removing the front element
public String dequeue() {
// check if queue empty
if (isEmpty()) {
return ("No items in the queue, cannot delete");
}
// adjust new size of array
front = (front + 1) % size();
count --;
return ("Deleting " + data[front]);
}
// enqueue value from rear
public String enqueue(int val) {
//if queue is empty, then check if
if (isFull()) {
return ("Queue full! Cannot add more values");
}
rear = (rear + 1) % max;
data[rear] = val;
count++;
return ("Adding " + val);
}
// return front element of queue
public int peek()
{
return data[front];
}
// check if the queue is empty or not
public Boolean isEmpty() {
return (size() == 0);
}
// check if the queue is full or not
public Boolean isFull() {
return (size() == max);
}
// returns the size of the queue
public int size() {
return count;
}
// public String toString(){
// for (int i = 0; i <= front; i++) {
// System.out.println(data[0]);
// }
// return "";
// }
}