From e1cb9f084aa3a574e20c708ca9ad5cb419c86f2a Mon Sep 17 00:00:00 2001 From: Mohanad Talat Date: Thu, 28 Apr 2022 05:59:06 +0200 Subject: [PATCH] Add SRTF file --- algorithms/Java/scheduling/SRTF.java | 115 +++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 algorithms/Java/scheduling/SRTF.java diff --git a/algorithms/Java/scheduling/SRTF.java b/algorithms/Java/scheduling/SRTF.java new file mode 100644 index 00000000..60c024a0 --- /dev/null +++ b/algorithms/Java/scheduling/SRTF.java @@ -0,0 +1,115 @@ +import java.util.ArrayList; +import java.util.Scanner; +import java.util.Collections; + + +public class SRTF implements Comparable{ + + int complete, burst_time, wait_time, id, arrival_time ; + int remain_burst_time, turnAround_time ; + + public SRTF(int burst_time,int id, int arrival_time) { + this.id = id ; + this.arrival_time = arrival_time ; + this.burst_time = burst_time ; + this.wait_time = 0 ; + this.complete = arrival_time ; + this.remain_burst_time = burst_time ; + } + + public int compareTo(SRTF process) { + return this.arrival_time - process.arrival_time ; + } + + public static void main(String[] args) { + + Scanner input = new Scanner(System.in) ; + System.out.print("Enter number of processes : "); + int n = input.nextInt() ; + + ArrayList arr = new ArrayList() ; + + for(int i=0 ; i indices = new ArrayList() ; + + for( int i=0 ; i0 ) { + indices.add(i) ; + arr.get(i).complete++ ; + } + + } + if(indices.size() != 0) { + int minBurst=arr.get(indices.get(0)).burst_time, idxMinBurst=indices.get(0) ; + for(int i=0 ; i