磁盘驱动调度

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
void display(int path[],int length)
{
	int sum=0;
	cout << "路径为:" << endl;
	cout << "PATH: ";
	for (int i = 0;i < length-1;i++)
	{
		sum += abs(path[i + 1] - path[i]);
		cout << path[i] << "--> ";
	}
	cout << path[length - 1] << endl;
	cout << "SumPath: " << sum;
	cout << endl;

}
void elevator(int s[],int length)
{
	int Path=0;
	int curPoint=s[0];
	int *path = new int[10];
	int *less = new int[10];
	int *more = new int[10];
	int Lcount = 0;
	int Mcount = 0;
	int Pcount = 1;
	path[0] = s[0];
	for (int i = 1;i < length;i++)
	{
		if (s[i] < curPoint)
		{
			less[Lcount] = s[i];
			Lcount++;
		}
		else 
		{
			more[Mcount] = s[i];
			Mcount++;
		}
	}
	sort(less,less+Lcount);
	sort(more,more+Mcount);
	for (int i = 0;i <Mcount;i++)
	{
		path[Pcount++] = more[i];
	}
	for (int i = Lcount-1;i >= 0;i--)
	{
		path[Pcount++] = less[i];
	}
	cout << "***********************ELEVATOR*****************************" << endl;
	display(path, Pcount);
}

void SSTF(int s[],int length)
{
	int *path = new int[10];
	int *pathFlag = new int[10];
	int curPoint = 0;
	int Pcount = 1;
	int num = 9;
	int a;
	path[0] = s[0];
	for (int i = 0;i < 10;i++)
	{
		pathFlag[i] = 0;
	}
	pathFlag[0] = 1;
	while (num--)
	{
		int min = 10000000;
       for (int i = 1;i < length;i++)
	   {
		  if ((min > abs(s[i] - s[curPoint]))&&curPoint!=i&&pathFlag[i]!=1)
		  {
			min = abs(s[i] - s[curPoint]);
			a = i;
		  }
	   }
	   curPoint = a;
	   pathFlag[curPoint] = 1;
	   path[Pcount++] = s[curPoint];

    }
	cout << "***********************SSFT*****************************" << endl;
	display(path, length);

}

int main()
{
   int S[10]= { 143,86,147,91,177,94,150,102,175,130 };
   int length = (int)(sizeof(S) / sizeof(*S));
   //cout << length;
  //elevator(S, length);
   elevator(S, length);
   cout << endl;
   SSTF(S, length);
   /*  SSTF(S,length);
   elevator(S,length);
   */
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值