当前位置: 首页>>代码示例>>C++>>正文


C++ PQueue::dequeue方法代码示例

本文整理汇总了C++中PQueue::dequeue方法的典型用法代码示例。如果您正苦于以下问题:C++ PQueue::dequeue方法的具体用法?C++ PQueue::dequeue怎么用?C++ PQueue::dequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PQueue的用法示例。


在下文中一共展示了PQueue::dequeue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(void)
{
	Queue bankQueue; //represents the line of customers in the bank/bank line
	PQueue eventListPQueue; //priority queue eventListPQueue for the event list

	bool tellerAvailable = true;
	loadIntoPriorityQueue(eventListPQueue); //load data into Priority Queue from file/Create and add arrival events to event list

	//waitTime = SUM(time of departure) - SUM(processing time) - SUM(time of arrival)/COUNT(EVENTS)
	unsigned int sumDepartureTime = 0;
	unsigned int sumProcessingTime = 0;
	unsigned int sumArrivalTime = 0;
	unsigned int eventCount = 0; //track how many customers came in
	float waitTime; //Calculated at the end

	cout << "Simulation Begins" << endl;

	while(!eventListPQueue.isEmpty()) //run while eventListPQueue is not empty
	{
		Event newEvent = eventListPQueue.peek();
		// Get current time
		unsigned int currentTime = newEvent.getTime(); // get time of newEvent
		if (newEvent.getType() == 'A') //check if newEvent is an arrival event
		{
			// Processes an arrival event.
			//processArrival(newEvent, eventListPQueue, bankQueue, tellerAvailable, currentTime);

			eventListPQueue.dequeue(); //Remove this event from the event list
			Event customer = newEvent; //customer referenced in arrivalEvent
			if (bankQueue.isEmpty() && tellerAvailable)
			{
				unsigned int departureTime = currentTime + customer.getLength();//currentTime + transaction time in arrivalEvent
				Event newDepartureEvent('D', departureTime, 0); //a new departure event with departureTime
				eventListPQueue.enqueue(newDepartureEvent);
				tellerAvailable = false;
			}
			else
			{
				bankQueue.enqueue(customer);
			}

			cout << "Processing an arrival event at time:\t" << customer.getTime() << endl;
			eventCount++; //count how many customers arrived
			sumArrivalTime += customer.getTime();
			sumProcessingTime += customer.getLength();
		}
		else
		{
			// Processes a departure event.
//			processDeparture(newEvent, eventListPQueue, bankQueue, tellerAvailable, currentTime);
			eventListPQueue.dequeue(); // Remove this event from the event list

			if(!bankQueue.isEmpty())
			{
				// Customer at front of line begins transaction
				Event customer = bankQueue.peek();
				bankQueue.dequeue();
				unsigned int departureTime = currentTime + customer.getLength(); //currentTime + transaction time in customer
				Event newDepartureEvent('D', departureTime, 0); //a new departure event with departureTime
				eventListPQueue.enqueue(newDepartureEvent);
			}
			else
			{
				tellerAvailable = true;
			}

			cout << "Processing a departure event at time:\t" << currentTime << endl; //temp
			sumDepartureTime += currentTime;
		}

	}

	waitTime = (float)(sumDepartureTime - sumProcessingTime - sumArrivalTime)/eventCount; //do the average wait time calculation

	cout << "Simulation Ends\n\n";
	cout << "Final Statistics:" << endl;
	cout << "\tTotal number of people processed: " << eventCount << endl;
	cout << "\tAverage amount of time spent waiting: " << waitTime << endl;

//	cout << "Bank Queue Contents:" << endl;
//	bankQueue.print();
//	cout << "Priority Queue Contents:" << endl;
//	eventListPQueue.print();
//	resultPrinterQueue(bankQueue); //print out the results
	return 0;
}
开发者ID:cwaffles,项目名称:cmpt225,代码行数:86,代码来源:BankSimApp.cpp


注:本文中的PQueue::dequeue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。