-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
There must be a change in the code to get specified output.
pages are 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9
``
#include<bits/stdc++.h>
using namespace std;
int main()
{
int f,p,j=0,x,pf=0,h=0,m,i,index,u;
vectoro;
std::vector::iterator it;
cout<<"Enter no of pages"<<endl;
cin>>p;
cout<<"Enter the reference string"<<endl;
for(i=0;i<p;i++)
{
cin>>x;
o.push_back(x);
}
cout<<"Enter no of frames"<<endl;
cin>>f;
vector<int>a(f,-1);
while(j<p)
{
m=0;
if(j<=f-1)
{
x=o.at(j);
a.at(j)=x;
++pf;
}
else
{
if(find(a.begin(), a.end(), o.at(j))!=a.end())
{
++h;
}
else
{
for(i=0;i<f;i++)
{
if(find(o.begin()+j+1,o.end(),a.at(i))!=o.end())
{
it=find(o.begin()+j+1,o.end(),a.at(i));
if(it-o.begin()>m)
{
m=(it-o.begin());index=i;
}
}
else
{
index=i;
break;
}
}
x=o.at(j);
a.at(index)=x;
++pf;
}
}
for(i=0;i<f;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
++j;
}
cout<<"No of page faults happen "<<pf<<endl;
cout<<"No of page hit happen "<<h;
}
Metadata
Metadata
Assignees
Labels
No labels