[软件设计/软件工程] 显示方法?

[复制链接]
发表于 2022-5-3 11:07:22
问题
我正在尝试实现一个循环队列,我想在其中显示我的队列,但唯一显示的是“这里是我的队列”,它只显示“空”。而不是打印出添加到队列中的客户端。我无法弄清楚为什么我的队列没有显示。我在此处插入图像以显示我想说的内容,请在此处输入图像描述。

我的队列将包括从 waitingRoom 移动到 CustomerQueue 的客户。最大客户数为 33。

这是我的代码:
  1. package hotelbooking;

  2. public class HotelBooking {
  3.     static int ROOM_CAPACITY = 33;

  4.     private static Customer[] waitingRoom = new Customer[ROOM_CAPACITY];
  5.     private static CustomerQueue hotelQueue = new CustomerQueue();
复制代码

这就是用户显示队列的方式。
  1. private static void ViewhotelQueue(Customer[] waitingRoom) {
  2.         System.out.println("Here is the queue: ");
  3.         hotelQueue.display();
  4.     }
复制代码
  1. package hotelbooking;

  2. public class CustomerQueue {
  3.     private Customer[] queArray = new Customer[HotelBooking.ROOM_CAPACITY];
  4.     private int front = 0;
  5.     private int end = 0;
  6.     private int maxLength = 0; //maximum length that was reached by the queue
  7.     private int currentSize = 0; //current circular Queue Size

  8.     public void add(Customer next) {

  9.         //if the queue is not full - check for the circular queue
  10.         if (!isFull()){
  11.             //add next customer
  12.             end = (end + 1)% queArray.length;
  13.             queArray[end] = next;
  14.             currentSize++;
  15.             //check the maxLength of the queue
  16.         }
  17.     }

  18.     public Customer remove() {
  19.         //if the queArray is not empty
  20.         if (!isEmpty()){
  21.         //remove customer
  22.         Customer removedCustomer = queArray[front];
  23.         //inform that not customer (return null)
  24.         queArray[front] = null;
  25.         front = (front + 1) % queArray.length;
  26.         currentSize--;
  27.         return removedCustomer;
  28.         }
  29.         return null;
  30.     }

  31.     public void display() {   
  32.         //list elements from front to end in the queArray
  33.         for (int i = front; i < currentSize; i++) {
  34.             System.out.println(queArray[(front+i)%queArray.length] + &quot;&quot;);
  35.             queArray[i].display();
  36.         }   
  37.     }
复制代码

有人可以帮助我,因为我一直在努力。

回答
太好了,您正在学习 java 和数据结构。 .

这可能会奏效。请将该元素添加到队列中并尝试显示



客户端队列类的一些更改
  1. private int end = -1;
  2. public void display() {   
  3.     //list elements from front to end in the queArray
  4.     for (int i = front; i < currentSize; i++) {
  5.         System.out.println(queArray[(front+i)%queArray.length] + &quot;&quot;);
  6.     }   
  7. }
复制代码






上一篇:警告:JSF1091:找不到文件动态内容的 mime 类型
下一篇:jq 获取对象键并在一个过滤器中更改其名称

使用道具 举报

Archiver|手机版|小黑屋|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved( ICP备案粤ICP备14042591号-1粤ICP14042591号 )

关于本站 - 版权申明 - 侵删联系 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表