java实现osFIFO页面置换算法
时间: 2023-11-26 13:47:07 浏览: 90
以下是Java实现OS FIFO页面置换算法的示例代码:
```java
import java.util.*;
public class OSFIFO {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入页面数:");
int pageNum = sc.nextInt();
System.out.print("请输入物理块数:");
int blockNum = sc.nextInt();
int[] pages = new int[pageNum];
System.out.print("请输入页面序列:");
for (int i = 0; i < pageNum; i++) {
pages[i] = sc.nextInt();
}
int[] blocks = new int[blockNum];
int count = 0;
for (int i = 0; i < pageNum; i++) {
boolean flag = false;
for (int j = 0; j < blockNum; j++) {
if (blocks[j] == pages[i]) {
flag = true;
break;
}
}
if (!flag) {
blocks[count % blockNum] = pages[i];
count++;
}
System.out.print("第" + (i + 1) + "次页面置换后的物理块状态:");
for (int j = 0; j < blockNum; j++) {
System.out.print(blocks[j] + " ");
}
System.out.println();
}
}
}
```
阅读全文