我需要对arrayList进行排序。 我可以使用Comparator并覆盖compare函数进行排序。 或者我可以自己编写合并排序函数并对ArrayList进行排序。
我在某处读到比较器排序使用冒泡排序算法。 由于Merge Sort的复杂性较低,我是否可以使用更容易实现的比较器进行合并排序。
I need to sort an arrayList. I can use a Comparator and override the compare function to sort. Or I can write a merge sort function on my own and sort the ArrayList.
I read somewhere that a comparator sorting uses bubble sort algorithm. Since Merge Sort has lesser complexity, do I go for merge sort over using a comparator which is easier to implement.
最满意答案
使用Comparator在ArrayList中强制对象的总排序,并使用Collection.sort(List list,Comparator c)对列表进行排序。 引用上面排序方法的Java文档 ,它使用一个迭代的mergesort算法,改编自蒂姆彼得的python列表排序(TimSort)。
Use a Comparator to impose the total ordering of the objects in the ArrayList and use Collection.sort(List list, Comparator c) to sort the list. Quoting the Java Documentation for the above sort method, it uses an iterative mergesort algorithm adapted from Tim Peter's list sort for python (TimSort).
哪个更好的排序对象的arrayList,使用比较器或Merge排序?(Which is better for sorting an arrayList of objects, Using the comparator or Merge sort?)我需要对arrayList进行排序。 我可以使用Comparator并覆盖compare函数进行排序。 或者我可以自己编写合并排序函数并对ArrayList进行排序。
我在某处读到比较器排序使用冒泡排序算法。 由于Merge Sort的复杂性较低,我是否可以使用更容易实现的比较器进行合并排序。
I need to sort an arrayList. I can use a Comparator and override the compare function to sort. Or I can write a merge sort function on my own and sort the ArrayList.
I read somewhere that a comparator sorting uses bubble sort algorithm. Since Merge Sort has lesser complexity, do I go for merge sort over using a comparator which is easier to implement.
最满意答案
使用Comparator在ArrayList中强制对象的总排序,并使用Collection.sort(List list,Comparator c)对列表进行排序。 引用上面排序方法的Java文档 ,它使用一个迭代的mergesort算法,改编自蒂姆彼得的python列表排序(TimSort)。
Use a Comparator to impose the total ordering of the objects in the ArrayList and use Collection.sort(List list, Comparator c) to sort the list. Quoting the Java Documentation for the above sort method, it uses an iterative mergesort algorithm adapted from Tim Peter's list sort for python (TimSort).
发布评论