FCFS Head Movement by Queue Program Code in C++ language .
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 |
#include <bits/stdc++.h> using namespace std; const int N=100005; int n; int head; int positions[N]; void fcfs(void) { int movement=0; for(int i=0; i<n; i++) { movement += abs(head - positions[i]); head = positions[i]; } printf("Total Head Movement %d Cylinders\n",movement); return; } int main() { cout<<"Initial Head Position: "; cin>>head; cout<<"Queue Size: "; cin>>n; cout<<"Queue:\n"; for(int i=0; i<n; i++) cin>>positions[i]; fcfs(); return 0; } /** 53 8 98 183 37 122 14 124 65 67 */ |