且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用比较最短寻道时间优先算法

更新时间:2023-02-26 16:50:43

首先,你要比较的的距离的轨道和头部位置之间,所以你必须使用绝对值在你的条件。

First, you want to compare the distance between the track and the head position, so you have to use the absolute value in your conditions.

if (Math.abs(nextHeadPosition - r1.getTrackNumber())  < Math.abs(nextHeadPosition -  r2.getTrackNumber()))

但你的方法修改的对象,这是不是一个好主意,因为你不知道如何 Col​​lections.sort()(我想这是你想要使用的)将使用它。你必须编写自己的排序算法,我认为。

But your compare method modifies the object, which is not a good idea since you don't know how Collections.sort() (I guess that's what you're trying to use) will use it. You have to write your own sorting algorithm I think.