VL-Algorithmen/T01/Aufgabe05/ArrayQueue.java
2024-05-21 14:48:00 +02:00

45 lines
866 B
Java

package T01.Aufgabe05;
/**
* Class to represent a ArrayQueue (using an array).
*/
public class ArrayQueue {
private Produkt queue[] = new Produkt[100];
/**
* Method to add a product to the Queue.
*
* @param produkt The product to add.
*/
public void add(Produkt produkt) {
for (int i = 0; i < this.queue.length; i++) {
if (queue[i] == null) {
int j = i;
while (j > 0) {
queue[j] = queue[j - 1];
j--;
}
break;
}
}
queue[0] = produkt;
}
/**
* Method to take a product from the Queue.
*
* @return The product taken from the Queue.
*/
public Produkt take() {
Produkt produkt = queue[0];
for (int i = 0; i < queue.length; i++) {
if (queue[i] == null) {
break;
}
queue[i] = queue[i + 1];
}
return produkt;
}
}