排序包含数字代表的对象数组。

huangapple go评论47阅读模式
英文:

Sort array of objects with representetive of numbers

问题

我尝试找到一个简单问题的最有信心的方法。
我有一个包含随机高度的矩形数组,我想使用不同的排序算法按高度对它们进行排序。

我找到了两个选项:

  • 创建另一个数组,其中包含表示高度的数字
  • 直接使用高度并对矩形进行排序

现在我不知道哪个更高效和更有信心地理解,以及我应该在哪个时刻选择其中一个。

非常感谢!

英文:

I try to find most confident way for a simple question.
I have an array of rectangles with random height, i want to sort them for height using different sorting algorithm.

I find out two option:

  • create another array of numbers that representate height
  • just use height and sort rectangles dirrectly

And now i don`t know witch one is more efficient and confident for understanding, and where is moment where i should choose one or another.

Thanks a lot)

答案1

得分: 0

使用Arrays.sort,并使用自定义的Comparator,按矩形的高度进行排序。

英文:

Use Arrays.sort with your custom Comparator sitting by rectangle’s height.

huangapple
  • 本文由 发表于 2023年5月6日 20:52:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188996.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定