gpt4 book ai didi

java - LinkedList队列实现

转载 作者:行者123 更新时间:2023-12-01 16:00:59 27 4
gpt4 key购买 nike

我有 LinkedList 队列,我正在尝试读取一个文件,其中包含队列中等待帮助的人员数量以及当时可以提供帮助的代理数量。我不知道检查他们是否忙碌或如何首先添加在队列中等待的人。谁能帮我?这是我到目前为止的代码。

public class WaitingQueue 
{
public int [] windows = 0; // every time we add some one check if location occupied
public int time = 0;
public int waitTime = 0;

public static void main(String args[])
{
Queue newQueue = new Queue();
try{

FileInputStream fn = new FileInputStream(args[0]);
BufferedReader br = new BufferedReader(new InputStreamReader(fn));
String line;

while((line = br.readLine()) != null)
{
time++; // happens every time window i busy
waitTime++ // increment waiTime
if ( time for people to arrive)
{
add people to the queue // have to have a queue for people waiting.
//use enque to add people.
}
if(window is open)
{
// move people from queue to window
// use dequeue
}

if(time = x;)
{
// add some people to list
}
}

//Close the input stream
outFile.close();
fn.close();
}
}catch (Exception e)
{/*Catches exception*/
System.err.println("An error has occured : " + e.getMessage());
}
}

最佳答案

--编辑--

我看到您的代码现在已用 Java 标记;我的代码更多是 C#/伪代码,因此您可能需要将其转换为 Java。

--编辑--

尽管这可能没有帮助。但我建议采用一种更面向实体的方法;像这样:

  • 代理、代理列表:应列出可用的代理
  • 客户、客户队列:应维护需要帮助的客户队列
  • 客户支持经理:
    • 应查看客服人员是否有空(不忙)
    • 使客户出队
    • 将其分配给可用的代理之一

在我的头顶上,看到以下内容:

客户:

public class Customer
{
string _strName;
public Customer(string strName) { _strName = strName; }
}

代理:

public class Agent
{
string _strName;
bool _bIsBusy = false;//
public bool IsBusy { get { return _bIsBusy; } }

Customer _Customer;
public Agent(string strName)
{
_strName = strName;
}

public void HandleCustomer(Customer theCustomer)
{
_Customer = theCustomer;
_bIsBusy = true;//Busy as long as the window is open.

//You might need something that doesnt block;
Thread.Sleep(5 * 1000); //Wait for time to simulate that agent is talking to customer

RemoveCustomer();//Done with the customer.
}

private void RemoveCustomer()
{
_Customer = null;
_bIsBusy = false;
}
}

经理:

根据可用性管理客户和代理的类

public class CustomerServiceBench
{
Queue<Customer> queCustomers = new Queue<Customer>();
List<Agent> lstAgents = new List<Agent>();
Thread thdService;

public CustomerServiceBench()
{
//Something along these lines.
thdService = new Thread(delegate() { WaitAndAddCustomerIfAgentIsAvailable(); });

}

private void AddCustomer()
{
//Add a dummy customer.
Random r = new Random(1231);
queCustomers.Enqueue(new Customer("Customer" + r.Next().ToString()));

Thread.Sleep(5 * 1000); //SpinWait.Once()...

}

private void WaitAndAddCustomerIfAgentIsAvailable()
{
//Thread1 to manage the

}
}

关于java - LinkedList队列实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3931510/

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