#include #include #include #define maxsize 4 //表示系统分配给进程maxsize-1个内存块 typedef int datatype; //顺序队列结构体的定义 typedef struct { datatype data[maxsize]; int front; int rear; }SeqQueue; //构造一个空的顺序队列 SeqQueue *InitQueue() { SeqQueue *p; p=(SeqQueue *)malloc(sizeof(SeqQueue)); p->front=p->rear=0; return p; } int number=0;//缺页计数 //入队 int EnQueue(SeqQueue *p,datatype x) { number++; cout<<"缺页计数"< p->rear=(p->rear+1)%maxsize; } //出队 void DeQueue(SeqQueue *p) { int x; x=p->data[p->front]; cout<<"页面"< } //输出顺序队列的内容 void display(SeqQueue *p) { int x,s; s=p->front; cout<<"内存块中的页面情况为"< { x=p->data[s]; cout< } } int justif(SeqQueue *p,datatype x) { int tem,s; s=p->front; while(s!=p->rear) {tem=p->data[s]; if(tem==x) {cout<<"数已在内存块中,请输入下一个" < s=(s+1)%maxsize;} return true; } main () { SeqQueue *Q; int i,total=0; int x; float f; Q=InitQueue(); cout<<"请输入"< total++; EnQueue(Q,x); } display(Q); while(1) { cout< if(!x) break; total++; if(justif(Q,x)) {DeQueue(Q); EnQueue(Q,x); } display(Q); } cout< cout<<"缺页中断率f="<< number<<"/"<