当前位置:网站首页>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 :

边栏推荐
- Open virtual machine kali2022.2 and install GVM
- Insert sort of sort
- 低端电脑如何深度学习秘籍-使用mistGPU计算平台
- 最早截止时间优先(EDF)
- 根据excel生成create建表SQL语句
- MySQL queries all descendant nodes under the parent node. When querying the user list, it is processed by multi-level (company) departments. According to reflection, it recurses the tree structure too
- Joern's code uses -devign
- High performance memory queue -disruptor
- Record the first article of so and so Xiao Lu
- Freemaker merges cells, uses if and else tags, and processes null and empty strings
猜你喜欢

NAT network address translation

object detection

Rsync+inotify to realize remote real-time synchronization

Branch and loop statements

Metasploit penetration MS7_ 010 exercise

Redis哨兵模式及集群

C language: understand the creation and destruction of function stack frames through an example

Install Nessus under Kali

Install pycharm

Starting point Chinese website font anti crawling technology web page can display numbers and letters, and the web page code is garbled or blank
随机推荐
easypoi导出表格带echars图表
Standard C language learning summary 7
C language review (pointer)
Detailed explanation of active scanning technology nmap
uniapp项目怎么连接手机真机调试
Blueberry pie Bluetooth debugging process
Add, delete, check and modify linked lists
开虚拟机KALI2022.2下安装GVM
Review of C language (byte alignment)
Basic usage and precautions of arrow function (= >) and three-point operator (...) in ES6 (this points to)
视频格式基础知识:让你了解MKV、MP4、H.265、码率、色深等等
Open virtual machine kali2022.2 and install GVM
Deployment of elk log analysis system
freemarker合并单元格,if、else标签的使用,null、空字符串处理
shell---循环语句练习
flow_ x+flow_ y---RGB
Pytorch installation - CPU version
Understanding of maximum likelihood estimation, gradient descent, linear regression and logistic regression
Remotely access the local website of services such as neo4j on the ECS
浅谈深分页问题