首页 > 代码库 > LRU
LRU
// LRU.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <queue>#include<vector>using namespace std;void LRU(){ vector<int> v; cout << "Input Array Length" << endl; int L1 = 0; int n = 0; int pos = 0; cin >> L1; cout << "Input Page Change Order" << endl; while (~scanf("%d",&n)) { if (v.size() < 3) { int pos = 0; for (int i = 0;i<v.size();i++) { if (v[i] == n) { //flag = true; pos = i; std::vector<int>::iterator it = v.begin()+pos; v.erase(it); } } v.push_back(n); } else { bool flag = false; int pos = 0; for (int i = 0;i<v.size();i++) { if (v[i] == n) { flag = true; pos = i; } } if (flag) { std::vector<int>::iterator it = v.begin()+pos; v.erase(it); v.push_back(n); } else { v.erase(v.begin()); v.push_back(n); } } for (int i = 0;i<v.size();i++) { cout << v[i] << " "; } cout << endl; }}int main(int argc, char* argv[]){ //printf("Hello World!\n"); LRU(); return 0;}
LRU
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。