1
대기열을 생성하고 객체를 대기열에 넣은 다음 대기열이 비어 있지 않으면 하나씩 차례로 대기열에서 제외합니다. 내가 겪고있는 문제는 체크 될 때마다 큐가 비어 있는다는 것입니다. Print는 각 객체를 큐에 넣은 후 큐에서 호출되며 큐의 내용을 잘 인쇄합니다.isEmpty()에 대해 객체가있는 대기열이 반환됩니다. Java
import java.util.*;
import java.io.*;
public class Processor2
{
private LinkedQueue queue = new LinkedQueue();
private int time = 0;
private int count = 100;
private int amount = 0;
private PrintWriter out;
private Person temp;
private boolean var;
private Random randomNum = new Random();;
private String turn;
private int popCount=0;
private int loopCount =0;
public void start()
{
amount = randomNum.nextInt(5);
amount += 5;
pop(amount, time);
sim();
}
public void pop(int num, int time)
{
for(int i=1; i<=num; i++)
{
Person pe = new Person(i, time, 0);
queue.enqueue(pe);
System.out.println(queue);
}
popCount += num;
}
public void sim()
{
try
{
out = new PrintWriter(new FileWriter("output.txt"));
while(loopCount<=100)
{
var = queue.isEmpty();
if(var=true)
{
System.out.println("queue is empty");
}
if(var=false)
{
Object temp = queue.dequeue();
double rand = Math.random();
if(rand < 0.5)
{
System.out.println("inside if else statement");
// does stuff with object //
loopCount++;
}
else
{
System.out.println("inside if else statement");
// does stuff with object //
loopCount++;
}
}
}
out.close();
}
catch (IOException ioe)
{
System.out.println("Error Writing to File: " + ioe);
}
}
}
이 큐의 IsEmpty 함수() 메소드를 아무 잘못 것 같다,하지만 여기있다되지 않습니다
public boolean isEmpty()
{
if(count == 0)
{
return true;
}
else
{
return false;
}
}
아마 큐에서 카운트가 올바르게 업데이트되지 않았습니까? – trutheality
LinkedQueue (자신의 클래스?)에 대한 소스를 보지 않고도 무슨 일이 일어나는지 말할 수는 없습니다. –
'return count == 0'이면 충분합니다.'if (bool) return true else else retrun false' ... – Xaerxess