Re: Sorting a vector based on another datas



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}

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

.



Relevant Pages

  • Re: Sorting a vector based on another datas
    ... int ranking = ... The TreeMap then may be accessed sorted by the key ... If you have a large number of elements bubble sort will be very slow -- ... Permutation sort, for example. ...
    (comp.lang.java.programmer)
  • Re: Need help in converting number to text
    ... convert an number to string: help sprintf ... map numbers to predefined strings: ... strings and index them. ... T = 'top noise ranking'; ...
    (comp.soft-sys.matlab)