-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIFO.java
More file actions
35 lines (28 loc) · 698 Bytes
/
Copy pathFIFO.java
File metadata and controls
35 lines (28 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class FIFO{
Pages pages;
ReferenceString str;
public FIFO(Pages pages) {
this.pages = pages;
}
public int simulate(ReferenceString str) {
this.str = str;
for (int i = 0; i < str.size(); i++)
if (!pages.hasSpace() && !pages.contains(str.get(i))) {
pages.pop();
pages.add(str.get(i));
}
else if (pages.hasSpace() && !pages.contains(str.get(i))) {
pages.add(str.get(i));
}
return pages.pageFaults;
}
public void print() {
pages.print();
}
public static void main(String[]args) {
ReferenceString str = new ReferenceString(.9, 10000);
str.fillRandomly();
FIFO fifo = new FIFO(new Pages(3));
System.out.println(fifo.simulate(str));
}
}