gpt4 book ai didi

c++ - 如何通过队列指针访问存储在节点中的类中的数据?

转载 作者:行者123 更新时间:2023-11-28 04:55:14 26 4
gpt4 key购买 nike

在我当前的任务中,我无法弄清楚如何访问这个特定的数据。

首先,作业要求从文件中提取数据以模拟商店的正常运营。唯一的问题是,被提取的数据是关于客户的。具体来说,就是客户何时进入队列以及收银员处理他们的订单需要多长时间。

现在我如何将客户数据存储在类数组中。

for(int i = 0; i < entries; i++)
{
/* !!!!!IMPORTANT!!!!!
* The way this program extracts file data assumes that the file will
follow a specific format
* results will vary heavily based on how the file is set up
*
* before docking points please make sure that the file follows the format
*
* "Number of entries"
* "Customer Number", "Arrival Time", "Service Time"
* "Customer Number", "Arrival Time", "Service Time"
* "Customer Number", "Arrival Time", "Service Time"
*/

xfiles >> dataEntry;
fileData[i].setNumber(dataEntry);
//inserts a number from the file into the "number" variable in the customer class.
xfiles >> dataEntry;
fileData[i].setArrival(dataEntry);
//inserts a number from the file into the "arrival" variable in the customer class.
xfiles >> dataEntry;
fileData[i].setServTime(dataEntry);
//inserts a number from the file into the "servTime" variable in the customer class.
}

xfiles.close();

它不包含在代码中,但有一行考虑了程序早期的条目。

在我的下一个区 block 中,我必须在一段时间内同时排队和处理客户。我知道我应该如何对它们进行排队,但我不太确定应该如何继续处理它们。就我现在所知道的,我相信我可能想做一个条件语句来检查数组中的某个客户是否已经排队。

我当前尝试访问的数据是类(class)中存储的到达时间。

类似的,
文件数据[i].returnArrival();

但是由于该类存储在队列中,所以我不确定如何访问它。

现在我如何让所有东西排队

for(int x = 0; x < 570; x++)
{
if(cusTime == x)
{
if(scully.isFull() = false)
scully.enqueue(fileData[cusTime]);
else if(mulder.isFull() = false)
mulder.enqueue(fileData[cusTime]);
else if(skinner.isFull() = false)
skinner.enqueue(fileData[cusTime]);
else
cout << "queues are full, disposing..\n";
}
cusTime++;
}

一开始我以为会是这样的

scully.returnFront()->temp->returnClass()->fileData.returnArrival();  

但我不确定,因为 temp 只是在队列类中声明的指针。

我的一个 friend 提出了另一个建议,他建议它可能是这样的,但我在运行代码时最终遇到了段错误。

scully.returnFront()->returnClass().returnArrival();

最佳答案

我觉得应该是这样的:

scully.returnFront().returnArrival()

因为您将数组中的项目排入队列。因此,returnFront() 检索一个项目,您的方法应该可以在该项目上使用。

关于c++ - 如何通过队列指针访问存储在节点中的类中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47275322/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com