标签:bsp public private int [] false add 队列 front
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(rear == queue.length - 1) 17 { 18 if(front == -1) 19 { 20 return false; 21 } 22 else 23 { 24 int position = 0; 25 26 for(int i = front + 1; i <= rear; i ++) 27 { 28 queue[position] = queue[i]; 29 30 position ++; 31 } 32 33 front = -1; 34 35 rear = position - 1; 36 } 37 38 } 39 40 rear ++; 41 42 queue[rear] = data; 43 44 return true; 45 } 46 47 public Object get() 48 { 49 if(front == rear) 50 { 51 return null; 52 } 53 54 front ++; 55 56 return queue[front]; 57 } 58 }
标签:bsp public private int [] false add 队列 front
原文地址:http://www.cnblogs.com/StringBuilder/p/7467041.html