Re: Sorting a vector based on another datas
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 19:20:21 -0000
Daniel Pitts wrote:
If you have a large number of elements bubble sort will be very slow --
it is the worst method to sort any kind of data.
Kai
Mostly correct. There are worse sorts than bubble sort.
Permutation sort, for example. Try every permutation until you find
one that is sorted.
Or Random Sort (aka BogoSort)...
My personal favourite, though, is Non-Sort. Here's a Java implementation in
case anyone needs it:
/**
* Non-sort, the fastest known probabilistic sorting algorithm.
*
* This is a probabilistic algorithm, and so is <em>not guaranteed</em>
* to return the correct answer, but — unlike many sorting
* algorithms — it <em>is</em> guaranteed that its runtime will
* not be affected by the order of the input elements. Indeed, the runtime
* is O(1) regardless of the input. However — and again, unlike
* many sorting algorithms — the order of the input <em>does</em>
* influence the probability of the algorithm producing the correct answer,
* reaching 100% for fully sorted inputs.
*
* @param list the list to be sorted.
* @return the sorted list. Callers should not assume this
* will be != to the input list.
*/
public static <X> java.util.List<X>
nonSort(java.util.List<X> list)
{
return list;
}
I also have an in-place version (plug-compatible with
java.util.Collections.sort(List)), if required.
-- chris
.
- References:
- Sorting a vector based on another datas
- From: zelao.itu@xxxxxxxxx
- Re: Sorting a vector based on another datas
- From: Kai Schwebke
- Re: Sorting a vector based on another datas
- From: Daniel Pitts
- Sorting a vector based on another datas
- Prev by Date: Re: javamail and mbox
- Next by Date: Re: Tricky regex question
- Previous by thread: Re: Sorting a vector based on another datas
- Next by thread: Re: Sorting a vector based on another datas
- Index(es):
Relevant Pages
|
|