Java LinkedList队列实现

Java LinkedList队列实现,java,linked-list,queue,Java,Linked List,Queue,我有LinkedList队列,我正在尝试读取一个文件,其中包含队列中等待帮助的人数以及当时可提供帮助的代理的数量。我不知道首先要检查他们是否忙,或者如何添加排队等候的人。有人能帮我吗?这是我目前掌握的代码 public class WaitingQueue { public int [] windows = 0; // every time we add some one check if location occupied public int time = 0; public i

我有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 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 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 

    }
}
公共类CustomerServiceBench
{
Queue queCustomers=新队列();
List-lstAgents=新列表();
线程服务;
公共客户服务台()
{
//沿着这条线的东西。
thdService=新线程(委托(){WaitAndAddCustomerIfAgentIsAvailable();});
}
私有void AddCustomer()
{
//添加一个虚拟客户。
随机r=新随机(1231);
queCustomers.Enqueue(新客户(“客户”+r.Next().ToString());
Thread.Sleep(5*1000);//SpinWait.Once()。。。
}
private void WaitAndAddCustomerIfAgentIsAvailable()
{
//Thread1来管理
}
}