Re: Sorting a vector based on another datas
- From: "Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx>
- Date: 31 Jan 2007 10:29:12 -0800
On Jan 31, 9:58 am, Kai Schwebke <realfreejac...@xxxxxxxx> wrote:
zelao....@xxxxxxxxx wrote:
Hey everybody, I'm having troubles with sorting a vector based in
another vector:
Example:
String [] models = {"Anna","Gisele","Yasmin"}
int [] ranking ={3,1,2}
....After sorting it might be this :
models = {"Gisele","Yasmin","Anna"}
ranking = {1,2,3}
Just put the strings as values in a TreeMap using
the ranking as key. The TreeMap then may be accessed sorted by the key
ordering (e.g. the values() method returns an ordered collection).
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.
.
- Follow-Ups:
- Re: Sorting a vector based on another datas
- From: Chris Uppal
- Re: Sorting a vector based on another datas
- References:
- Sorting a vector based on another datas
- From: zelao.itu@xxxxxxxxx
- Re: Sorting a vector based on another datas
- From: Kai Schwebke
- Sorting a vector based on another datas
- Prev by Date: Re: Looking for java programmer to join project
- Next by Date: Re: Sorting a vector based on another datas
- 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
|