/** lembar kerja 03, queue*/ public class MyCircularArrayQueue { private T[] theArray; private int front, back, size; public MyCircularArrayQueue() { theArray = (T[]) new Object [10] ; } public MyCircularArrayQueue (int defaultCapacity) { theArray = (T[]) new Object[defaultCapacity]; } public void MakeEmpty() { front = back = size = 0; } public boolean isEmpty() { if(size==0) return true; else return false; } public int getSize() { return size; } public T dequeue() { size--; if(front==theArray.length) { front = 0; } T y = theArray[front]; front++; return y; } public void enqueue (T x) { if(!isFull() && back!=theArray.length) { theArray[back] = x; } else if(back == theArray.length &&!isFull()) { back = 0; theArray[back] = x; } else if(isFull())
{ arrayDoubling(); theArray[back] = x; } else
}
System.out.println("kondisi belom terdeteksi"); back++; size++;
private boolean isFull() { if(size==theArray.length) return true; else return false; } private void arrayDoubling() { T[] thearray = (T[]) new Object[theArray.length * 2]; for (int k=0 ; k < theArray.length ; k++) { thearray[k] = theArray[k]; } theArray = thearray; } }//end clas