package yanhaochen;
public class hello {
public static void main ( String[ ] args) {
}
}
class ArrayQueue {
private int maxSize;
private int front;
private int rear;
private int [ ] arr;
public ArrayQueue ( int arrmaxsize) {
maxSize= arrmaxsize;
arr = new int [ maxSize] ;
front = - 1 ; rear = - 1 ;
}
public boolean isFull ( ) {
return rear == maxSize- 1 ;
}
public boolean isEmpyt ( ) {
return rear == front;
}
public void addQueue ( int n) {
if ( isFull ( ) ) {
System. out. println ( "队列已满,无法插入" ) ;
return ;
}
rear++ ;
arr[ rear] = n;
}
public int getQueue ( ) {
if ( isEmpyt ( ) ) {
throw new RuntimeException ( "队列为空" ) ;
}
front++ ;
return arr[ front] ;
}
public void show ( ) {
if ( isEmpyt ( ) ) {
System. out. println ( "队列为空" ) ;
return ;
}
for ( int i= 0 ; i< arr. length; i++ ) {
System. out. printf ( "arr[%d]=%d\n" , arr[ i] , i) ;
}
}
public int headQueue ( ) {
if ( isEmpyt ( ) ) {
throw new RuntimeException ( "队列为空" ) ;
}
return arr[ front+ 1 ] ;
}
}