-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShortest_Seek_Time_First.cpp
58 lines (58 loc) · 1.05 KB
/
Shortest_Seek_Time_First.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
#include<iostream>
#include<stdlib.h>
using namespace std;
class sstf_disk
{
int ref[100];
int pos,size;
int find_short(int );
public:
void getdata();
void total_move();
};
void sstf_disk::getdata()
{
cout<<"Enter the current position of head ";
cin>>pos;
cout<<"Enter the size of queue : ";
cin>>size;
cout<<"Enter the request for tracks : ";
for(int i=0;i<size;i++)
cin>>ref[i];
}
int sstf_disk::find_short(int num)
{
int min=99999,ind,temp;
for(int i=0;i<size;i++)
{
if(ref[i]!=-1)
{
temp=abs(num-ref[i]);
if(min>temp)
{
min=temp;
ind=i;
}
}
}
return ind;
}
void sstf_disk::total_move()
{
int num=pos,move=0,ind;
for(int i=0;i<size;i++)
{
ind=find_short(num);
move+=abs(num-ref[ind]);
num=ref[ind];
ref[ind]=-1;
}
cout<<"Total head movements : "<<move;
}
int main()
{
sstf_disk sstf;
sstf.getdata();
sstf.total_move();
return 0;
}