Untitled
unknown
plain_text
2 years ago
2.6 kB
3
Indexable
using System; namespace Jobs { class Program { static int[] jobsTimeRec = { 90, 46, 11, 35, 79, 95, 13, 92, 11, 97 }; static int[] jobsExeTime = { 23, 15, 50, 12, 6, 47, 18, 37, 50, 22 }; static int[] jobsPriority = { 8, 2, 5, 1, 5, 2, 8, 9, 5, 2 }; public static void Main(string[] args) { Console.WriteLine("tests"); Console.WriteLine(); SortFCFS(Program.jobsTimeRec); SortPRIORITY(jobsPriority); SortSJF(jobsExeTime); } public static void SortFCFS(int[] arr) { int max = arr.Length - 1; for (int i = 0; i < max; i++) { int nLeft = max - i; for (int j = 0; j < nLeft; j++) { if (arr[j] > arr[j + 1]) { var tempOb = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tempOb; } } } Console.WriteLine("Sorted by Time Received (FirstComeFirstServed)"); Array.ForEach(arr, Console.WriteLine); Console.WriteLine(); } public static void SortPRIORITY(int[] arr) { int max = arr.Length - 1; for (int i = 0; i < max; i++) { int nLeft = max - i; for (int j = 0; j < nLeft; j++) { if (arr[j] < arr[j + 1]) { var tempOb = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tempOb; } } } Console.WriteLine("Sorted by Priority (Priority)"); Array.ForEach(arr, Console.WriteLine); Console.WriteLine(); } public static void SortSJF(int[] arr) { int max = arr.Length - 1; for (int i = 0; i < max; i++) { int nLeft = max - i; for (int j = 0; j < nLeft; j++) { if (arr[j] > arr[j + 1]) { var tempOb = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tempOb; } } } Console.WriteLine("Sorted by Quickest Execution Time (ShortestJobFirst)"); Array.ForEach(arr, Console.WriteLine); Console.WriteLine(); } } }
Editor is loading...