-
Notifications
You must be signed in to change notification settings - Fork 0
/
SJF.cs
39 lines (31 loc) · 1.04 KB
/
SJF.cs
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
namespace CPU_ProcessScheduling
{
public static class SJF
{
public static void SJFSchedule(Process[] Inputs)
{
Console.WriteLine("<<<<<<<<<<<<<<<<<<<<SJF>>>>>>>>>>>>>>>>>>>>");
Process[] Copy = new Process[Inputs.Length];
Inputs.CopyTo(Copy, 0);
int len = Inputs.Length;
int time = 0, smallest;
for (int i = 0; i < len; i++)
{
while (Copy[i].BurstT > 0)
{
smallest = i;
for (int j = 0; j < len; j++)
{
if (Copy[j].ArrivalT <= time && Copy[j].BurstT > 0 && Copy[j].BurstT < Copy[smallest].BurstT)
smallest = j;
}
Inputs[smallest].WaitingT = time - Copy[smallest].ArrivalT;
time += Copy[smallest].BurstT;
Copy[smallest].BurstT = 0;
}
}
Process.AvgWTTAT(Inputs);
}
}
}