Re: Sorting a vector based on another datas



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.

.



Relevant Pages

  • Re: Reader feelings management OR rank your chapters OR "pre-crit"
    ... of learning process....and the ranking in it self may give some "ahaa". ... more of an exploratory sort of writer, so I want to say things like "You ... the main character and their ... The politics -- ...
    (rec.arts.sf.composition)
  • Re: Individual Rankings
    ... There is a ranking system I've heard called the "Swiss System" that is ... The Swiss system uses three different numbers to sort players. ... After each round, the players are sorted by the method above ...
    (rec.sport.billiard)
  • Re: Sync the Rankings
    ... How should I go about being able to make [Ranking] sort in 'ascending' order ... corresponding to the 'descending' order of [AggScore] automatically, so i don't have to manually change all the rankings to fit the current score? ... I then would highlight the Team and AggScore columns, sort that by the AggScore in 'descending' order. ...
    (comp.databases.ms-access)
  • Re: automatic sorting
    ... Have you tried using Pivot tables to build views. ... descending order, and ranking them etc. ... I have a similar spreadsheet updated via a link, and have 60 tabs of pivots ... avoid having to manually sort the data in the rankings sheet each month. ...
    (microsoft.public.excel.misc)
  • Re: Sorting a Soccer PointsTable
    ... I am trying to sort a Soccer table. ... I have used the Functions of Rank and Large to sort the ranking according to ... Goal difference and Points for the teams. ...
    (microsoft.public.excel.worksheet.functions)