简体   繁体   English

使用compareTo排序对象的双向链接列表的最佳方法是什么

[英]What is the best way to sort a doubly linked list of objects using compareTo

I have a doubly linked list of objects, and have a comparable interface in order to compare these objects. 我有一个双重链接的对象列表,并且有一个可比较的接口以便比较这些对象。 I'm just wondering, is there a standard/ best sort algorithm used to sort the list in this case? 我只是想知道,在这种情况下,是否使用标准/最佳排序算法对列表进行排序?

thanks for any help! 谢谢你的帮助!

You have a LinkedList<T extends Comparable> instance then the best way is to use the facility function Collections.sort . 您有一个LinkedList<T extends Comparable>实例,那么最好的方法是使用设施函数Collections.sort

If you have your custom data structure then you could make it implement the List<T> interface to be able to use the Collections methods (which includes sort and many others). 如果您具有自定义数据结构,则可以使其实现List<T>接口,以便能够使用Collections方法(包括sort和许多其他方法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM