我必须在Java中创建一个程序,其中包含从我的队列类创建的队列数组,如下所示 -
class Queue1{ //each line at the supermarket
public Queue1(int s){ //constructor
maxSize = s;
pplLines = new long[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
public void insert(long j){ //put item at rear of queue
if(rear == maxSize - 1) //deal with wraparound
rear = -1;
pplLines[++rear] = j; //increment rear and insert
nItems++; //one more item
}
public long remove(){ //take item from front of queue
long temp = pplLines[front++]; //get value and increment front
if(front == maxSize) //deal with wraparound
front = 0;
nItems--; //one less item
return temp;
}
public long peekFront(){ //peek at front of queue
return pplLines[front];
}
public boolean isEmpty(){ //true if queue is empty
return (nItems == 0);
}
public boolean isFull(){ //true if queue is full
return (nItems == maxSize);
}
public int size(){ //number of items in queue
return nItems;
}
public void display(){ //display contents of queue
for (int i = 0; i < nItems; i++) {
System.out.println(pplLines[(front + i) % maxSize]);
}
}
}//ends queue class
那么如何将队列类引用到以此
开头的数组中public SuperMarket(int num_clerks,int line_size){
之后我创建了一系列队列我需要找到最短的一行来插入一个客户,我必须输入超市里可用的职员/行数,我该如何将其添加到我的SuperMarket类中?
感谢您的帮助!
答案 0 :(得分:0)
如果您执行类似
的操作public SuperMarket(int num_clerks, int line_size){
List<Queue1> clerks = new ArrayList<Queue1>();
for(int i; i< num_clerks; i++){
clerks.add(new Queue1(line_size))
}
}