队列方法问题是,这会删除数据吗?

huangapple 未分类评论42阅读模式
英文:

Queue method problem white problem is it will delete the data?

问题

在程序中添加这段代码时,出现了问题。

while (true) {
    boolean h1Status = false, h2Status = false, h3Status = false;

    if (h1.isEmpty() == false) {
        if (h1.last() == LastBuffer + 1) {

            LastBuffer++;
            System.out.println("将包裹 " + LastBuffer + " 从输入缓冲区移到输出缓冲区");
            h1Status = true;
        }

    } else if (h2.isEmpty() == false) {
        if (h2.last() == LastBuffer + 1) {
            LastBuffer++;
            System.out.println("将包裹 " + LastBuffer + " 从输入缓冲区移到输出缓冲区");

            h2Status = true;
        }

    } else if (h3.isEmpty() == false) {
        if (h3.last() == LastBuffer + 1) {

            LastBuffer++;
            System.out.println("将包裹 " + LastBuffer + " 从输入缓冲区移到输出缓冲区");
            h3Status = true;
        }
    } else if (h1Status == false && h2Status == false && h3Status == false) {
        break;
    }
}

错误信息为:

Exception in thread "main" EmptyListException: 链表为空。
    at LinkedList.removeFromTail(LinkedList.java:54)
    at LinkedQueue.HeadCheck(LinkedQueue.java:56)
    at ParcelQueues.main(ParcelQueues.java:124)

我在队列中添加了两个方法:

public int last()
{	
    Object item = qll.removeFromHead();
    int i = (int)item;
    return i;	
}

public int HeadCheck()
{	
    Object item = qll.removeFromTail();
    int i = (int)item;
    qll.addToTail(item);
    return i;	
}

你如何解决这个问题?我解决了大约3小时。这就像是一个包裹的配送安排。当一个包裹输出到缓冲区时,它需要检查所有的队列(h1、h2、h3)是否可以输出到缓冲区。最终的输出应该是(1 2 3 4 5 6 7)。

英文:

When i add this in the program,it has a problem.

while (true) {
    boolean h1Status = false, h2Status = false, h3Status = false;

    if (h1.isEmpty() == false) {
        if (h1.last() == LastBuffer + 1) {

            LastBuffer++;
            System.out.println("Move parcel " + LastBuffer + " from input buffer to output buffer directly");
            h1Status = true;
        }

    } else if (h2.isEmpty() == false) {
        if (h2.last() == LastBuffer + 1) {
            LastBuffer++;
            System.out.println("Move parcel " + LastBuffer + " from input buffer to output buffer directly");

            h2Status = true;
        }

    } else if (h3.isEmpty() == false) {
        if (h3.last() == LastBuffer + 1) {

            LastBuffer++;
            System.out.println("Move parcel " + LastBuffer + " from input buffer to output buffer directly");
            h3Status = true;
        }
    } else if (h1Status == false && h2Status == false && h3Status == false) {
        break;
    }
}

and the error

Exception in thread "main" EmptyListException: List is empty.
    at LinkedList.removeFromTail(LinkedList.java:54)
    at LinkedQueue.HeadCheck(LinkedQueue.java:56)
    at ParcelQueues.main(ParcelQueues.java:124)

I added two of the method in queue

public int last()
{	
	Object item=qll.removeFromHead();
	
	int i=(int)item;
	return i;
	
}

another:

public int HeadCheck()
{	
	Object item=qll.removeFromTail();
	
	int i=(int)item;
	qll.addToTail(item);
	return i;
	
}

how can I solve the problem?I solved it around 3 hours.It like a Parcel arrangement for delivery.When 1 output to the buffer.It needs to check all of the queue(h1,h2,h3)to the buffer.The Finally output is (1 2 3 4 5 6 7)

huangapple
  • 本文由 发表于 2020年4月10日 01:25:49
  • 转载请务必保留本文链接:https://java.coder-hub.com/61126783.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定