资源简介
可以对给出的任意的磁盘请求序列、计算平均寻道长度; 要求可定制磁盘请求序列长度、磁头起始位置、磁头移动方向。
测试:假设磁盘访问序列:98,183,37,122,14,124,65,67;读写头起始位置:53,方向:磁道增加的方向。

代码片段和文件信息
#include
#include
using namespace std;
int a;//当前磁道号
int direction; //磁头方向
int num; //输入磁道总数
const int Maxqueue = 200; //定义队列最大数
typedef struct node
{ //磁道结构体
int value;
int visted;
}cidao;
cidao queue[Maxqueue];
void shuru1()
{
cout<<“请依次磁道号:“< for(int i = 0;i cin>>queue[i].value;
cout<<“输入初始磁道号:“;
cin>>a;
}
void shuru2()
{
cout<<“请输入需要的磁道总数“< cin>>num;
}
void initial()
{
for(int i = 0;i {
queue[i].value = -1;
queue[i].visted = 0;
}
}
void sstf()
{
int total = 0;//总移动的柱面数
int p;
int current;
for(int i = 0;i queue[i].visted = 0;
current = a;
for(int i = 0;i {
p = 0;
while(queue[p].visted!=0)
{
p++;
}
for(int j = p;j {
if((queue[j].visted==0)&&(abs(current-queue[p].value)>abs(current-queue[j].value)))
{
p = j;
}
}
cout< total += abs(queue[p].value-current); //计算总柱面
queue[p].visted = 1;
current = queue[p].value;
}
cout< }
void scan()
{
int total = 0;
int p;
int current;
int index = 0;
cout<<“输入方向:1或0“< cin>>direction;
cout< for(int i = 0;i queue[i].visted = 0;
current = a;
int temp = 0;
for(int i = 0;i {
for(int j = i;j {
if(queue[i].value>queue[j].value)
{
temp = queue[i].value;
queue[i].value = queue[j].value;
queue[j].value = temp;
}
}
}
for(int i = 0;i {
if(queue[i].value>=a)
{
index = i;
break;
}
}
cout< if(direction == 1)
{
for(int i = index;i {
cout< }
for(int i =index - 1;i>=0;i--)//回转
{
cout< }
}
else
{
for(int i =index ;i>=0;i--)//往外
{
cout< }
for(int i = index;i {
cout< }
}
}
void main()
{
//initial();
//shuru2();
//shuru1();
//sstf();
initial();
shuru2();
shuru1();
scan();
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 68608 2016-12-09 20:22 最短寻道时间优先\Debug\最短寻道时间优先.exe
文件 555340 2016-12-09 20:22 最短寻道时间优先\Debug\最短寻道时间优先.ilk
文件 822272 2016-12-09 20:22 最短寻道时间优先\Debug\最短寻道时间优先.pdb
文件 558 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\cl.command.1.tlog
文件 11794 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\CL.read.1.tlog
文件 258 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\CL.write.1.tlog
文件 2 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\li
文件 2 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\li
文件 2 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\li
文件 2 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\li
文件 1018 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\li
文件 2428 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\li
文件 326 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\li
文件 156568 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\main.obj
文件 257024 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\vc110.idb
文件 339968 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\vc110.pdb
文件 553 2016-12-09 19:50 最短寻道时间优先\最短寻道时间优先\Debug\最短寻道时间优先.Build.CppClean.log
文件 80 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\最短寻道时间优先.lastbuildstate
文件 1745 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug\最短寻道时间优先.log
文件 2369 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\main.cpp
文件 4024 2016-12-08 19:29 最短寻道时间优先\最短寻道时间优先\最短寻道时间优先.vcxproj
文件 942 2016-12-08 19:29 最短寻道时间优先\最短寻道时间优先\最短寻道时间优先.vcxproj.filters
文件 7143424 2016-12-09 20:25 最短寻道时间优先\最短寻道时间优先.sdf
文件 939 2016-12-08 16:14 最短寻道时间优先\最短寻道时间优先.sln
..A..H. 21504 2016-12-09 20:25 最短寻道时间优先\最短寻道时间优先.v11.suo
目录 0 2016-12-09 20:22 最短寻道时间优先\最短寻道时间优先\Debug
目录 0 2016-12-09 19:50 最短寻道时间优先\Debug
目录 0 2016-12-08 19:29 最短寻道时间优先\最短寻道时间优先
目录 0 2016-12-09 20:25 最短寻道时间优先
----------- --------- ---------- ----- ----
............此处省略2个文件信息
相关资源
- CCS FFT c语言算法
- 小波变换算法 c语言版
- 3des加密算法C语言实现
- DES加密算法C语言实现
- 线性回归算法c语言实现
- 基于C语言的模拟退火算法
- C语言实现的DES对称加密算法
- 用VC6.0实现多边形扫描线填充算法
- c语言编写的货郎担算法
- Em算法(使用C++编写)
- STM32烧写算法flash包
- 永磁同步电机的FOC控制算法
- Proteus仿真:PID算法输出.rar
- 一个模糊PID温度控制算法源代码
- 经典滤波算法
- KMP算法C语言程序
- SVM算法实现(源码+文档)
- 算法A律U律实现
- 人工蜂群算法.docx
- BlowFish加密算法
- C语言常用算法源代码
- c++数组快排算法
- 算法表达式求值.cpp
- PID算法.c
- QR二维码C++源码 算法实现
- 基于opencv漫水填充算法综合
- 信息学奥赛一本通——算法部分
- 银行家算法分配资源的模拟实现(m
- C语言程序设计50例.docx
- 常见排序算法比较.cpp
评论
共有 条评论