import java.util.Scanner;
public class Queue {
public static void main(String[] args) {
System.out.println(
"Please enter integer number what represent how many elements will be in the queue and press Enter: ");
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
sc.close();
QueueMake queue = new QueueMake(size);
queue.add(5);
queue.add(1);
queue.add(7);
queue.add(3);
for (int i = 0; i < queue.size; i++) {
System.out.print(queue.extract() + " ");
}
}
}
class QueueMake {
int size;
int head;
int tail;
int[] data;
QueueMake(int size) {
data = new int[this.size = size];
}
void add(int value) {
if (++tail == size)
tail = 0;
data[tail] = value;
}
int extract() {
if (++head == size)
head = 0;
return data[head];
}
boolean isEmpty() {
return head == tail;
}
}Answer provided by AssignmentExpert.com