dopage.cpp

来自「页面置换算法代码」· C++ 代码 · 共 60 行

CPP
60
字号
#include <iostream>
#include <fstream>
#include "fifo.h"
#include "lru.h"
#include "scr.h"

using std::ifstream;
using std::cout;

int main(int argc,char *argv[])
{
	if (argc != 4)
	{
		cout << "Error input!";
		exit(1);
	}

	ifstream file( argv[3] );
	if (!file.is_open())
	{
		cout << "Not fount page file!";
		exit(2);
	}

	int page_max = atoi(argv[1]);
	if (page_max < 3)
		page_max = 3;
	cout << "There are " << page_max << " pages AND ";

	Mem_page *mp;

	if(!strcmp(argv[2], "fifo"))
	{
		cout <<"Using FIFO Algorithm" << endl;
		mp = new Fifo_page(page_max);
	}
	else if(!strcmp(argv[2], "lru"))
	{
		cout <<"Using LRU Algorithm" << endl;
		mp = new Lru_page(page_max);
	}
	else
	{
		cout <<"Using SCR Algorithm" << endl;
		mp = new Scr_page(page_max);
	}

	char page_id[10];

	while (!file.eof())
	{
		file.getline(page_id, sizeof(page_id));
		mp->do_page( atoi(page_id) );
		mp->show_page();
	}
	file.close();
	//mp->show_page();
	delete mp;
	return 0;
}

⌨️ 快捷键说明

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