⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waitingline.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
import dslib.dispenser.LinkedQueueUos;
import dslib.base.FormatUos; 

/**	A waiting line for a simulation. */
public class WaitingLine
{
	/**	The repesentation of the waiting line. */
	protected LinkedQueueUos waitingLine;

	/**	The total amount of time the customers spent waiting in the line. */
	protected int summationWaitingTimes;

	/**	Create the waiting line.
		Analysis: Time = O(1) */
	public WaitingLine()
	{
		summationWaitingTimes = 0;
		waitingLine = new LinkedQueueUos();
	}

	/**	Are there any customers waiting?
		Analysis: Time = O(1) */
	public boolean isEmpty()
	{
		return waitingLine.isEmpty();
	}

	/**	The first customer of the waiting line.
		Analysis: Time = O(1)
		PRECONDITION
			!isEmpty() */
	public Customer first() throws WaitingLineEmptyException
	{
		if (isEmpty())
			throw new WaitingLineEmptyException("No first customer when the line is empty.");
	
		return (Customer)waitingLine.item();
	}

	/**	Customer leaves the waiting line.
		Analysis: Time = O(1)
		PRECONDITION
			!isEmpty() */
	public void deleteFirst() throws WaitingLineEmptyException
	{
		if (isEmpty())
			throw new WaitingLineEmptyException("Customer cannot be deleted when the line is empty.");

		summationWaitingTimes += Simulation.time - first().arrivalTime;
		waitingLine.deleteItem();
	}

	/**	Customer joins the waiting line.
		Analysis: Time = O(1) */
	public void join(Customer c)
	{
		waitingLine.insert(c);
		System.out.println(FormatUos.pad("", 4, 'r') + FormatUos.pad("", 7, 'c')
				+ FormatUos.pad("enter queue", 14, 'l')
				+ FormatUos.pad(c.number, 9, 'r'));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -