当前位置:网站首页>Shortest seek time first (SSTF)
Shortest seek time first (SSTF)
2022-07-28 07:20:00 【▀】
| from 100 Track number begins | |
| Next track accessed | Moving distance ( Track number ) |
| 90 | 10 |
| 58 | 32 |
| 55 | 3 |
| 39 | 16 |
| 38 | 1 |
| 18 | 20 |
| 150 | 132 |
| 160 | 10 |
| 184 | 24 |
| Average seek length :27.5 | |
#include<iostream>
#include<algorithm>
#include<list>
#include <fstream>
#include<iterator>
#include<vector>
#include <functional>
#include<cmath>
using namespace std;
class SSTF
{
public:
int id;// Number
int dis;// distance
SSTF()
{
dis = 0;
}
friend ostream & operator <<(ostream &o, const SSTF &s);
friend istream & operator >>(istream &i ,SSTF &s);
bool operator ==(const SSTF &s)
{
if (s.id==this->id)
{
return true;
}
return false;
}
bool operator>(const SSTF &s)
{
if (this->id>s.id )
{
return true;
}
return false;
}
bool operator<(const SSTF &s)
{
if (this->id < s.id)
{
return true;
}
return false;
}
SSTF & operator=(const SSTF &s)
{
this->id = s.id;
this->dis = s.dis;
return *this;
}
};
ostream & operator <<(ostream &o, const SSTF &s)
{
o << s.id << "\t" << s.dis;
return o;
}
istream & operator >>(istream &i, SSTF &s)
{
i >> s.id ;
return i;
}
void main()
{
fstream out("data.txt");
list<SSTF>v;
copy(istream_iterator<SSTF>(out),istream_iterator<SSTF>(),back_inserter(v));
copy(v.begin(), v.end(), ostream_iterator<SSTF>(cout));
float num=0.0;
int begin = 100;
v.sort();
cout << "\n The result is :" << endl;
cout << " The order of access is :" << endl;
while (v.size()!=0)
{
transform(v.begin(), v.end(), v.begin(), [begin](SSTF &s)->SSTF {s.dis = abs(begin - s.id);return s; });
list<SSTF>::iterator min = min_element(v.begin(), v.end(), [](const SSTF &s1,const SSTF &s2)->bool {return s1.dis > s2.dis ? false : true; });
begin = min->id;
cout << *min << endl;
num += min->dis;
v.remove(*min);
}
cout <<" Average seek time :"<< (num / 9) << endl;
cin.get();
}data.txt

test result :

边栏推荐
- guava之限流RateLimiter
- Shell--- circular statement practice
- MySQL excludes holidays and calculates the date difference
- Log in to Oracle10g OEM and want to manage the monitor program, but the account password input page always pops up
- 232(母)转422(公)
- 2018-cvpr-Gesture Recognition: Focus on the Hands
- Overview of distributed system development
- easypoi一对多,合并单元格,并且根据内容自适应行高
- 用户态vs内核态、进程vs线程
- Redis sentinel mode and cluster
猜你喜欢

Metasploit penetration MS7_ 010 exercise

MySQL excludes holidays and calculates the date difference

5G 商用第三年:无人驾驶的“上山”与“下海”

Pytorch - storage and loading model

深入剖析单例模式的实现

学生执勤问题

Install pycharm

Event_ Loop event loop mechanism

How did tensor leak your memory / video memory

WiFi one click connection configuration of raspberry pie
随机推荐
easypoi导出隔行样式设置
ThreadLocal那些事
joern运行后.joernindex数据库无内容
Tailing microelectronics B91 general development board integrated into the trunk of openharmony community
最早截止时间优先(EDF)
OJ questions about fast and slow pointers in linked lists
Generate create table creation SQL statement according to excel
codesensor:将代码转化为ast后再转化为文本向量
软考证书还能这样用!拿到证书=获得职称?
Install Nessus under Kali
Standard C language learning summary 5
Review of C language (variable parameters)
最短寻道时间优先(SSTF)
anaconda3无法打开navigator的解决办法
Standard C language learning summary 3
Freemaker exports word with tables and multiple pictures to solve the repetition and deformation of pictures
RAID disk array
Insert sort of sort
flow_ x+flow_ y---RGB
登录进oracle10g的oem,想管理监听程序却总是弹出帐号密码输入页面