#include<iostream.h>
#include<math.h>
class List;
class item
{
public:
friend class List;
private:
item(int p=0,int s=0,int b=0,int l=0){page=p;sign=s;block=b;locate=l;next=NULL;}
item *next;
int page;
int sign;
int block;
int locate;
};
class List
{
public:
List(){list=0;}
List(int p=0,int s=0,int b=0,int l=0){list=new item(p,s,b,l);}
int check(int p);
int insert(int p,int s,int b,int l);
int print();
int append(int p,int s,int b,int l);
int length();
void reverse();
private:
item *list;
item *end();
};
int List :: print()
{
if(list==0)
return 0;
cout<<"页号 标志 主存块号 磁盘地址"<<endl;
item *pt=list;
while(pt)
{
cout<<" "<<pt->page<<" "<<pt->sign<<" "<<pt->block<<" "<<pt->locate<<endl;
pt=pt->next;
}
cout<<endl;
return 1;
}
int List::append(int p,int s,int b,int l)
{
item *pt=new item(p,s,b,l);
if(list==0)
list=pt;
else
{
(end())->next=pt;
}
return 1;
}
item *List::end()
{
item *prv,*pt;
for(prv=pt=list;pt;prv=pt,pt=pt->next)
;
return prv;
}
int List::insert(int p,int s,int b,int l)
{
item *pt=new item(p,s,b,l);
pt->next=list;
list=pt;
return 1;
}