public class CircleQueue {
private final int Max_Size=8;//队列的最大容量
private int front;// 队首位置
private int end;// 队尾位置
private Plot plot[];
public CircleQueue(){
front=0;
end=0;
plot=new Plot[Max_Size];
}
//入队列
public void add(Plot p){
if(isFull()){
throw new RuntimeException("队列已满,入队失败!");
}
plot[end]=p;
end=(end+1)%Max_Size;
}
public Plot pop(){
if(isEmpty()){
//throw new RuntimeException("队列为空,出队失败!");
System.out.println("队列为空,出队失败!");
return null;
}
Plot p=plot[front];
front = (front+1)%Max_Size;
return p;
}
public boolean isFull(){
return (front==end) ;
}
public boolean isEmpty(){
//return (end+1)%MAX_SIZE == front;
if((end+1)%Max_Size == front){
return true;
}else{
return false;
}
}
}
//图中的一个节点
public class Plot {
int x,y;//位置:x行,y列
char c;//*或@
boolean isVisted=false;
}