zoukankan      html  css  js  c++  java
  • 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!
    ");
        LRU();
        return 0;
    }
  • 相关阅读:
    oo第八次作业--5,6,7次作业总结
    OO前三次作业总结
    软工总结
    黄衫感想博客
    软工结对编程博客
    软工第一次阅读
    软工第0次作业
    OO第四次博客
    OO第三次博客
    OO第二次博客
  • 原文地址:https://www.cnblogs.com/yifi/p/6672677.html
Copyright © 2011-2022 走看看