-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIFO.cs
53 lines (47 loc) · 1.2 KB
/
FIFO.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
class Process
{
public double pid, AT, BT;
public Process(double pid, double AT, double BT)
{
this.pid = pid;
this.AT = AT;
this.BT = BT;
}
}
public class FIFO
{
public static void Main(string[] args)
{
Process[] pro = {
new Process(1, 0, 3),
new Process(2, 2, 5),
new Process(3, 4, 2)
};
FIFOAlgorithm.FIFO(pro);
}
}
class FIFOAlgorithm
{
public static void FIFO(Process[] processes)
{
Queue<Process> queue = new Queue<Process>();
float TWT = 0, TAT = 0;
foreach (Process process in processes)
{
if (queue.Count != 0)
{
TAT += queue.Peek().BT;
}
queue.Enqueue(process);
Console.WriteLine("Process " + process.pid + " is being executed.");
TWT += TAT - (float)process.AT;
queue.Dequeue();
}
float avgWT = TWT / processes.Length;
float avgTAT = TAT / processes.Length;
Console.WriteLine("Average Waiting Time: " + avgWT);
Console.WriteLine("Average Turnaround Time: " + avgTAT);
}
}