资源介绍
#include
#include
using namespace std;
typedef struct page
{
int num;
int bl_num;
int i;
struct page *next;
}p_list,*p_ptr;
typedef struct memory
{
int data;
struct memory *next;
}m_list,*m_ptr;
int wst[8][8];
int v,z,qy_f=0,qy_l=0,yh;
void change_add(int bl_num,int me_s,int lo_ad)
{
int b,c;
yh=lo_ad/me_s;
b=lo_ad%me_s;
c=bl_num*me_s+b;
cout<<"页号和偏移量:"<next=NULL;
s=k;
l=new p_list;
l->next=NULL;
r=l;
for(m=0;mnum=m;
p->bl_num=-1;
p->i=0;
r->next=p;
r=p;
}
r->next=NULL;
for(m=0;mdata=-1;
s->next=q;
s=q;
}
s->next=NULL;
}
void show_page(p_ptr l)
{
p_ptr r;
r=l->next;
cout<<"页号"<<" "<<"块号"<<" "<<"状态位"<num<<" "<bl_num<<" "<i<next;
}
}
void show_memory(m_ptr k)
{
m_ptr s;
s=k->next;
cout<<"主存"<data<next;
}
}
void init_wst()
{
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
wst[i][j]=rand()%2;
}
}
}
void print_wst()
{
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
cout<next;
while(s!=NULL)
{
if(s->data==-1)
{
i++;
s=s->next;
}
else
{
return i;
}
}
return i;
}
int mzf(m_ptr k,int page_num)
{
int i=0;
m_ptr s;
s=k->next;
while(s!=NULL)
{
if(s->data==page_num)
{
return 1;
}
else
{
s=s->next;
}
}
return 0;
}
int FIFO(p_ptr &l,m_ptr &k,int page_num,int bl_nu)
{
int m;
p_ptr r;
m_ptr s,t,u;
u=new m_list;
s=k->next;
r=l->next;
while(r!=NULL)
{
if(r->num==page_num&&r->i!=0)
{
break;
}
if(r->num==page_num&&r->i==0)
{
r->i=1;
r->bl_num=bl_nu;
qy_f++;
}
r=r->next;
}
if(pdk(k)!=0&&pdk(k)==z)
{
while(s!=NULL)
{
if(s->data==page_num)
{
show_page(l);
show_memory(k);
return 0;
}
s=s->next;
}
s=k->next;
for(m=0;mnext;
}
s->data=page_num;
z--;
show_page(l);
show_memory(k);
return 0;
}
if(pdk(k)==0)
{
if(mzf(k,page_num)==1)
{
show_page(l);
show_memory(k);
return 0;
}
if(mzf(k,page_num)==0)
{
while(s->next!=NULL)
{
t=s;
s=s->next;
}
t->next=NULL;
r=l->next;
while(r!=NULL)
{
if(r->num==s->data)
{
r->bl_num=-1;
r->i=0;
}
r=r->next;
}
delete s;
u->data=page_num;
u->next=k->next;
k->next=u;
show_page(l);
show_memory(k);
}
}
}
/*int LRU(p_ptr &l,m_ptr &k,int page_num,int bl_nu)
{
int m;
p_ptr r;
m_ptr s,t,u;
u=new m_list;
s=k->next;
r=l->next;
while(r!=NULL)
{
if(r->num==page_num&&r->i!=0)
{
break;
}
if(r->num==page_num&&r->i==0)
{
r->i=1;
r->bl_num=bl_nu;
qy_l++;
}
r=r->next;
}
if(pdk(k)!=0&&pdk(k)==z)
{
while(s!=NULL)
{
if(s->data==page_num)
{
show_page(l);
show_memory(k);
return 0;
}
s=s->next;
}
s=k->next;
for(m=0;mnext;
}
s->data=page_num;
z--;
show_page(l);
show_memory(k);
return 0;
}
if(pdk(k)==0)
{
if(mzf(k,page_num)==1)
{
while(s->next!=NULL)
{
t=s;
if(s->data==page_num)
{
}
}
show_page(l);
show_memory(k);
return 0;
}
if(mzf(k,page_num)==0)
{
while(s->next!=NULL)
{
t=s;
s=s->next;
}
t->next=NULL;
r=l->next;
while(r!=NULL)
{
if(r->num==s->data)
{
r->bl_num=-1;
r->i=0;
}
r=r->next;
}
delete s;
u->data=page_num;
u->next=k->next;
k->next=u;
show_page(l);
show_memory(k);
}
}
}*/
void main()
{
int lo_ad,bl_nu,bl_sz,ra_bl;
p_ptr page;
m_ptr memory;
cout<<"请输入页表长度:"<>v;
cout<<"请输入块数:"<>z;
cout<<"请输入块的长度(b):"<>bl_sz;
init_wst();
init_page(page,memory);
show_page(page);
show_memory(memory);
while(lo_ad!=-1)
{
ra_bl=rand_bl();
cout<<"请输入逻辑地址:"<>hex>>lo_ad;
change_add(ra_bl,bl_sz,lo_ad);
if(yh>v-1)
{
cout<<"error"<
- 上一篇: 操作系统设计与实现 操作系统设计与实现
- 下一篇: c#培训班报名系统课设作业.zip