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


C++ FIFO::clear方法代码示例

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


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

示例1: main

int main() {

	ifstream printdata("printdata.txt"); //make a stream
	List<job> printQueue;//this queue is going to be used for FIFO processing

	//create a whole bunch of dummy variables to put in the list
	int eyeD, tstamp, numP;
	char auth;
	job temp;




	while (printdata >> eyeD) {
		//read in data
		temp.id = eyeD;
		printdata >> tstamp;
		temp.timestamp = tstamp;
		printdata >> auth;
		temp.user = auth;
		printdata >> numP;
		temp.pages = numP;
		printQueue.push_back(temp); // callthe lists pushback method to add it to the back of the FIFO queue.
	}

	//create a dummy front job
	job frontJob;
	frontJob = printQueue.pop_front(); //get the first element in the fifo queue.
	int clock = frontJob.timestamp;
	//begin FIFO processing
	FIFO<job> feefo; //create a fifo list type
	feefo.push(frontJob); //place it at the beginning of the queue
	int stoptime = 0;
	zachresults << "Processing and calculating FIFO queue." << endl;
	job printing; //printing will hold the current job that is printing
	//initialize all of our stats
	int minwait = 0, maxwait = 0, totalwait = 0, jobsprocessed = 0;
	double avgwait;

	bool busyPrinter = false; // the printer isn't busy, so tell the truth, you goon
	do {
		if (!busyPrinter) { //if the printer isn't busy, begin printing the next job in the fifo queue
			printing = feefo.pop(clock);
			zachresults << "Starting print id " << printing.id << " at " << clock << endl;
			stoptime = clock + printing.length();
			zachresults << "This job will end at " << stoptime << endl;
			zachresults << "This job waited " << printing.waittime << " seconds." << endl;
			if (printing.id != 165896) { //don't collect wait time stats on the first print job. it doesn't wait.
				if(minwait == 0)	{
					minwait = printing.waittime;
					maxwait = printing.waittime;
					jobsprocessed++;
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				else {
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				if (printing.waittime < minwait) {
					minwait = printing.waittime;
				}
				if (printing.waittime > maxwait) {
					maxwait = printing.waittime;
				}
				
			}
			busyPrinter = true; //the printer is now busy
		}
		if (!printQueue.is_empty()) { //as long as we're still pulling jobs off the queue as they arrive, run this block of code
			frontJob = printQueue.pop_front(); //get the next job and put it in our frontjob variable
			while (busyPrinter && clock < frontJob.timestamp) { //while the printr is busy and the next job hasn't arrived yet, increment the clock
				clock++;
				if (clock == frontJob.timestamp) { //add a job to the queue once our clock hits its timestamp
					feefo.push(frontJob);
					zachresults << "Job " << frontJob.id << " arrived at " << clock << endl;
				}
				if (stoptime == clock) { //the print job is done once this stoptime is satisfied
					busyPrinter = false;
				}
			}
		}
		else {
			while (busyPrinter) {//run this once all of the jobs from printdata.txt are in our queue
				clock++;
				if (stoptime == clock) {
					busyPrinter = false;
				}
			}
		}
	} while (!feefo.isempty()); //bail once all of our jobs are done

	zachresults << "The minimum wait time was " << minwait << " seconds." << endl;
	zachresults << "The maximum wait time was " << maxwait << " seconds." << endl;
	zachresults << "The average wait time was " << avgwait << " seconds" << endl;
	zachresults << "The total wait time was " << totalwait << " seconds." << endl;
	//tidy everything up before we move on to SJF
	printdata.close();
	feefo.clear();
	printQueue.clear();
//.........这里部分代码省略.........
开发者ID:zfleeman,项目名称:program7,代码行数:101,代码来源:main.cpp


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