Add given Class (Queue / Schlenglein)

This commit is contained in:
Matti 2024-05-07 14:50:29 +02:00
parent 68b4e77761
commit f09b77cde5

View File

@ -1,4 +1,30 @@
package part3.aufg2;
public class Schlenglein {
public class Schlenglein <T>{
private Object[] myArray;
private int numberOfElements;
private int maxSize;
public Schlenglein(){
this.numberOfElements = 0;
this.maxSize = 100;
myArray = new Object[this.maxSize];
}
public void add(T t){
this.myArray[this.numberOfElements] = t;
this.numberOfElements++;
}
public T get(){
T retValue = (T) this.myArray[0];
for (int i=0; i<this.numberOfElements; i++){
this.myArray[i] = this.myArray[i+1];
}
this.numberOfElements--;
return retValue;
}
public int size(){
return this.numberOfElements;
}
}