将值推入队列时遇到问题

时间:2019-04-23 12:40:49

标签: java simulation

我正在用Java编写一个单队列系统仿真程序。在我的程序中,我想将一个值压入队列,我的程序读取该行,但队列大小返回0。

这部分将值推入队列

EL nextEvent = new EL(clock);
q.push(nextEvent); // pushing the first incoming customer in queue
cust--; // still waiting for other customers

这是我的队列

public class queue {

EL[] q;
int head;
int tail;
int rear;
int cap = 10000;
int count;

public queue(int cap) {
    super();
    head = 0;
    tail = 0;
    this.q = new EL[cap];
}


public void push(EL item){
    if (!isFull()){
        rear = (rear + 1) % cap;
        q[rear] = item;
        count++;
    }
}

public EL pop() {
    if (isEmpty()) {
        return null;
    }
    int tmp = head;
    head = (head + 1) % cap;
    return q[tmp];
}

// measures the size of a queue
public double size(){return count;}
public boolean isEmpty(){return (size() == 0);} // checks if queue is empty or not
public boolean isFull(){return (size() == cap);} // checks if queue is full or not
}

这是我的EL课

public class EL {
double atmQEnterTime;
double atmQLeaveTime;
double atmLeaveTime;

public EL(double atmQEnterTime){
    this.atmQEnterTime = atmQEnterTime;
    atmQLeaveTime = 0;
    atmLeaveTime = 0;
}
public double getTotTime() {return atmLeaveTime - atmQEnterTime;}
public double getQWaitTime() {return atmQLeaveTime - atmQEnterTime;}
}

我不知道为什么它没有将任何值推入队列。

0 个答案:

没有答案