int List::length()
{
int cnt=0;
item *pt=list;
for(;pt;pt->next,cnt++)
;
return cnt;
}
int List::check(int p)
{
item *pt=list;
int a=-1;
for(;pt;pt=pt->next)
{
if(pt->page==p&&pt->sign==1)
a=pt->block;
}
return a;
}
void List::reverse()
{
item *pt,*prv,*tmp;
prv=NULL;
pt=list;
list=end();
while(pt!=list)
{
tmp=pt->next;
pt->next=prv;
prv=pt;
pt=tmp;
}
list->next=prv;
}
int checkp(int n);
int main()
{
List list(0,1,5,11);
list.append(1,1,8,12);
list.append(2,1,9,13);
list.append(3,1,1,21);
list.append(4,0,-1,22);
list.append(5,0,-1,23);
list.append(6,0,-1,121);
//list.reverse();
list.print();
char a[12]={'+','+','*','I','O','-','M','+','I','O','+','I'};
int b[12]={70,50,15,21,56,40,53,23,37,78,1,84};
int m=0,n,j;
for(int i=0;i<12;i++)
{
cout<<"*************************"<<"第"<<i+1<<"步["<<a[i]<<"]操作!"<<"*************************"<<endl;
cout<<"请输入该操作对应的页号:";
cin>>n;
m=list.check(n);
j=checkp(n);
if(j==1)
{
if(m!=-1)
cout<<"该指令的物理地址为:"<<n<<b[i]<<endl;
else
cout<<"*缺页中断,页号:"<<n<<endl;
}