今天把队列写了
package com.Queue;
public interface QueueADT<T> {
public void push(Object obj) throws Exception;
public Object pop() throws Exception;
public boolean isEmpty();
public int size();
public String toString();
}
package com.Queue;
public class Queue implements QueueADT {
private Object data[];
private int front;
private int rear;
private int maxsize;
private int size;
public Queue(int maxsize) {
this.maxsize = maxsize;
this.data = new Object[maxsize];
front = 0;
rear = -1;
size = 0;
}
@Override
public void push(Object obj) throws Exception {
if (rear == maxsize) {
throw new FullOutException("Queue");
}
size++;
data[++rear] = obj;
}
@Override
public Object pop() throws Exception {
if (front > rear){
throw new IndexOutOfBoundsException("溢出");
}
size--;
return data[front++];
}
@Override
public boolean isEmpty() {
return front > rear;
}
@Override
public int size() {
return size;
}
}