Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <deque>
- #include <algorithm>
- #include <queue>
- int main()
- {
- using namespace std;
- deque<int> page{ 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 };
- deque<int> frame;
- unsigned count = 0;
- while (!page.empty())
- {
- int nowUsed = page.front();
- page.pop_front();
- if (find(frame.begin(), frame.end(), nowUsed) != frame.end())
- continue;
- if (frame.size() == 3)
- {
- ++count;
- cout << frame.front() << ' ';
- frame.pop_front();
- }
- frame.push_back(nowUsed);
- cout << "缺页次数" << count << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment