//
public class Queue{
private int maxSize;
private int[] queArray;
private int front;
private int nItems;
//
public Queue(int s){
maxSize = s;
queArray = new int[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
//
public void insert(int newData){
if(rear == maxSize - 1){
rear = -1;
}
queArray[++rear] = newData;
nItems++;
}
//
public int remove(){
int temp = queArray[front++];
if(front == maxSize){
front = 0;
}
nItems--;
return temp;
}
public int peekFront(){
return queArray[front];
}
public boolean isEmpty(){
if(nItems == maxSize){
return true;
}else{
return false;
}
}
public int size(){
return nItems;
}
}
/////////////////////////////////////////////////////////////////////////////////////
class Link{
public int data;
public next;
public Link(int data){
this.data = data;
}
}
class FirstLastList{
private first;
privare last;
public boolean isEmpty(){
if(first == null){
return true;
}else{
return false;
}
}
public boolean insertLast(int data){
Link newLink = new Link(data);
if(isEmpty){
first = newLink;
}else{
last.next = newLink;
}
last = newLink;
}
public int deleteFirst(){
int temp = first.data;
if(first.next == null){
last = null;
}
first = first.next;
return temp;
}
}
//
public class QueueLink{
private FirstLastLink;
public LinkQueue(){
theList = new FristLastLink();
}
public void insert(int data){
theList.insertLast(data);
}
public int delete(){
return theList.deleteFrist();
}
}