-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.cpp
More file actions
44 lines (43 loc) · 967 Bytes
/
scan.cpp
File metadata and controls
44 lines (43 loc) · 967 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int> readyQueue{98, 183, 37, 122, 14, 124, 65, 67};
int currentPointer = 53;
int totalSeekTime = currentPointer;
int firstIndex;
sort(readyQueue.begin(), readyQueue.end());
//goes left first, then right
for (int i = 0; i < readyQueue.size(); i++)
{
if (readyQueue[i] > currentPointer)
{
firstIndex = i - 1;
break;
}
}
cout << "\nSchedule: ";
cout << currentPointer << " ";
int i = firstIndex;
if (i > 0)
{
while (i >= 0)
{
cout << readyQueue[i] << " ";
currentPointer = readyQueue[i];
i--;
}
}
if (readyQueue[0] != 0)
cout << 0 << " ";
currentPointer = 0;
i = firstIndex + 1;
while (i < readyQueue.size())
{
cout << readyQueue[i] << " ";
currentPointer = readyQueue[i++];
}
totalSeekTime += readyQueue[readyQueue.size() - 1];
cout << "\nTotal seek time: " << totalSeekTime;
return 0;
}