1 public class ArrayQueue 2 { 3 private int front = -1; 4 5 private int rear = -1; 6 7 private Object[] queue; 8 9 public ArrayQueue(int size) 10 { 11 queue = new Object[size]; 12 } 13 14 public boolean add(Object data) 15 { 16 if(isFull() == true) 17 { 18 return false; 19 } 20 21 if((rear == queue.length - 1) && (front != -1)) 22 { 23 int position = 0; 24 25 for(int i = front + 1; i <= rear; i ++) 26 { 27 queue[position] = queue[i]; 28 29 position ++; 30 } 31 32 front = -1; 33 34 rear = position - 1; 35 } 36 37 queue[++ rear] = data; 38 39 return true; 40 } 41 42 public Object get() 43 { 44 if(isEmpty() == true) 45 { 46 return null; 47 } 48 49 return queue[++ front]; 50 } 51 52 public boolean isEmpty() 53 { 54 if(front == rear) 55 { 56 return true; 57 } 58 else 59 { 60 return false; 61 } 62 } 63 64 public boolean isFull() 65 { 66 if((rear == queue.length - 1) && (front == -1)) 67 { 68 return true; 69 } 70 else 71 { 72 return false; 73 } 74 } 75 76 }