package queue;
import java.util.Queue;
public class QueueDemo {
private int allCount;//队列最大长度
private String[] queueArray;//队列
private int front;//队列头
private int rear;//队列尾
private int nItems;//元素个数
public QueueDemo(int s){
allCount = s;
queueArray = new String[allCount];
front = 0;
rear = -1;
nItems = 0;
}
public boolean insert(String s){
if(nItems == allCount){
return false;
}
if(rear == allCount - 1){
rear = -1;
}
queueArray[++rear] = s;
nItems ++;
return true;
}
public String remove(){
if(nItems == 0){
return null;
}
nItems --;
return s;
}
public String peekFront(){
return queueArray[front];
}
public boolean isFull(){
if(nItems == allCount){
return true;
}
return false;
}
public boolean isEmpty(){
if(nItems == 0){
return true;
}
return false;
}
public int size(){
return nItems;
}
}
import java.util.Queue;
public class QueueDemo {
private int allCount;//队列最大长度
private String[] queueArray;//队列
private int front;//队列头
private int rear;//队列尾
private int nItems;//元素个数
public QueueDemo(int s){
allCount = s;
queueArray = new String[allCount];
front = 0;
rear = -1;
nItems = 0;
}
public boolean insert(String s){
if(nItems == allCount){
return false;
}
if(rear == allCount - 1){
rear = -1;
}
queueArray[++rear] = s;
nItems ++;
return true;
}
public String remove(){
if(nItems == 0){
return null;
}
String s = queueArray[front];
if(front = allCount - 1){
front =0;
}
nItems --;
return s;
}
public String peekFront(){
return queueArray[front];
}
public boolean isFull(){
if(nItems == allCount){
return true;
}
return false;
}
public boolean isEmpty(){
if(nItems == 0){
return true;
}
return false;
}
public int size(){
return nItems;
}
}