-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiskSchedulingPolicy(SSTF).cpp
47 lines (38 loc) · 1.02 KB
/
DiskSchedulingPolicy(SSTF).cpp
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
#include <bits/stdc++.h>
using namespace std;
int findShortest(int head, int *queue, int n)
{
int mini = INT_MAX, index;
for (int i = 0; i < n; i++)
if (mini > abs(head - queue[i]))
{
mini = abs(head - queue[i]);
index = i;
}
return index;
}
int main()
{
int head, n, range, total = 0;
cout << "Enter the head position: ";
cin >> head;
cout << "\nEnter the number of requests: ";
cin >> n;
cout << "\nEnter the range of cylinder: ";
cin >> range;
int queue[n];
cout << "\nEnter the cylinder numbers for the requests: ";
for (int i = 0; i < n; i++)
cin >> queue[i];
cout << "\nThe order of execution: " << endl;
for (int i = 0; i < n; i++)
{
int index = findShortest(head, queue, n);
total += abs(head - queue[index]);
cout << head << "->" << queue[index] << endl;
head = queue[index];
queue[index] = INT_MAX;
}
cout << "\nTotal Headmovements: " << total;
return 0;
}