-
Notifications
You must be signed in to change notification settings - Fork 1
/
FCFS-Disk-Scheduling.cpp
61 lines (49 loc) · 1.18 KB
/
FCFS-Disk-Scheduling.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// C++ program to demonstrate
// FCFS Disk Scheduling algorithm
#include <bits/stdc++.h>
using namespace std;
void FCFS(int *arr, int head , int n)
{
int seek_count = 0;
int distance, cur_track ,HEAD = head;
for (int i = 0; i < n; i++)
{
cur_track = arr[i];
// calculate absolute distance
// calculating the difference for the head movement
distance = abs(cur_track - head);
// increase the total count
seek_count += distance;
// accessed track is now new head
head = cur_track;
}
cout << "Total number of seek operations = "
<< seek_count << endl<<endl;
// Seek sequence would be the same
// as request array sequence
cout << "Seek Sequence of tracks is " << endl;
cout<<HEAD;
for (int i = 0; i < n; i++) {
cout <<" -> "<< arr[i];
}
}
int main()
{
int n;
cout<<"\nEnter number of requests : ";
cin>>n;
cout<<"\nEnter the requests:\n";
// request array
int *arr;
arr = new int[n];
for (int i = 0; i < n ; i++)
{
cin>>arr[i];
}
int head;
cout<<"\nEnter the head position\n";
cin>>head;
cout<<endl;
FCFS(arr, head , n);
return 0;
}