📄 main.cpp
字号:
#include"os.h"
void main()
{
cout<<"请输入内存中期望的页数:";
int ynum;
cin>>ynum;
stack memstk(ynum);
cout<<"请输入页号序列个数:(序列号是随机生成的)";
int snum;
cin>>snum;
// cout<<memstk.getstacksize()<<endl;
int *a=new int[snum];
for(int k=0;k<snum;k++)
a[k]=rand()%10;
for(k=0;k<snum;k++)
cout<<a[k]<<" ";
cout<<endl;
//int a[21]={7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,1,7,0,1};
int i=0;
while(memstk.size()<ynum)
{
Memory temp;
temp.pagenum=a[i];
temp.times=0;
int n=memstk.search(a[i]);
if(n!=-1)
{
memstk.exchange(temp,n);
memstk.print();
cout<<"页号为:"<<temp.pagenum<<"已在内存中,现又被访问一次"<<endl;
}
else
{
memstk.push(temp);
memstk.print();
cout<<"内存中仍然有剩余的空间,所以该页直接进入内存"<<endl;
}
// cout<<memstk.size()<<endl;
i++;
}
while(i<snum)
{
Memory temp;
temp.pagenum=a[i];
temp.times=0;
int n=memstk.search(a[i]);
if(n!=-1)
{
memstk.exchange(temp,n);
memstk.print();
cout<<"页号为:"<<temp.pagenum<<"已在内存中,现又被访问一次"<<endl;
}
else
{
n=memstk.searchmin();
int pagenum=memstk.pagenum(n);
memstk.exchange(temp,n);
memstk.print();
cout<<"页号为:"<<temp.pagenum<<"的页,"
<<"替换页号为:"<<pagenum<<"的页"<<endl;
}
i++;
}
delete []a;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -