Re: Sorting a vector based on another datas
- From: Lew <lew@xxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 08:00:19 -0500
zelao.itu@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}
These are vectors, but not Vectors. The conventional Java term for these structures is "array".
It's because i sorted the models' vector based on ranking vector, and
it could accept duplicate datas;
So how can i do that ??????
I think about do a bubble sort in ranking vector and when the
condition met (like ranking[0] > ranking[1]) I swap both vectors, but
I don't think it's the best way. There is another one ?
You'd be better off declaring a class type that holds the value and rank, then sort an array or List of that type based on a Comparator that examines the rank.
- Lew
.
- Follow-Ups:
- Re: Sorting a vector based on another datas
- From: zelao.itu@xxxxxxxxx
- Re: Sorting a vector based on another datas
- References:
- Sorting a vector based on another datas
- From: zelao.itu@xxxxxxxxx
- Sorting a vector based on another datas
- Prev by Date: Re: jsp
- Next by Date: Web start on os X : Cannot open associated file.
- Previous by thread: Sorting a vector based on another datas
- Next by thread: Re: Sorting a vector based on another datas
- Index(es):
Relevant Pages
|