LRU
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章