Add given Class (Queue / Schlenglein)
This commit is contained in:
parent
68b4e77761
commit
f09b77cde5
@ -1,4 +1,30 @@
|
|||||||
package part3.aufg2;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user