ghorardim

FCFS (Disk)

Nov 12th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const long long mx=1e5;
  5.  
  6. int n;
  7. int head;
  8. int positions[mx+5];
  9.  
  10. void fcfs(void)
  11. {
  12. int i,movement;
  13.  
  14. movement = 0;
  15. for(i=1; i<=n; i++)
  16. {
  17. movement += abs(head - positions[i]);
  18. head = positions[i];
  19. }
  20. printf("Total Head Movement %d Cylinders\n",movement);
  21. return;
  22. }
  23.  
  24. int main()
  25. {
  26. int i;
  27.  
  28. printf("Initial Head Position: ");
  29. cin>>head;
  30.  
  31. printf("Queue Size: ");
  32. cin>>n;
  33.  
  34. printf("Queue:\n");
  35. for(i=1; i<=n; i++) cin>>positions[i];
  36.  
  37. fcfs();
  38.  
  39. return 0;
  40. }
Add Comment
Please, Sign In to add comment