-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIFO_PageReplacement.java
54 lines (45 loc) · 1.48 KB
/
FIFO_PageReplacement.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.*;
public class FIFO_PageReplacement{
public void fifoPageReplacementAlgo(List<Integer>request, int frames){
Queue<Integer>queue=new LinkedList<>();
int hit=0;
int miss=0;
for(int i=0;i<request.size();i++){
if(queue.size()<3){
if(!queue.contains(request.get(i))){
miss++;
queue.add(request.get(i));
}
else{
hit++;
}
}
else if(queue.contains(request.get(i))){
hit++;
}
else{
queue.poll();
queue.add(request.get(i));
miss++;
}
System.out.println(queue);
}
System.out.println("No. of hit "+ hit);
System.out.println("No. of miss "+ miss);
}
public static void main(String[] a){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no. of frames in main memeory");
int frames=sc.nextInt();
System.out.println("Enter the page no. demanded by CPU in a sequence");
System.out.println("Enter -1 to stop");
List<Integer>request=new ArrayList<>();
int page=sc.nextInt();
while(page!=-1){
request.add(page);
page=sc.nextInt();
}
FIFO_PageReplacement fifo= new FIFO_PageReplacement();
fifo.fifoPageReplacementAlgo(request, frames);
}
}