0

I've created a tournament ranking program which has two classes so far. A Team class and a Scoring class. The team class holds instance variables such as a elo score (double) based on win/loss/ties. The Scoring class takes an arraylist of Teams and the plan is to create a new Arraylist of teams in order from highest elo to lowest elo.

My question is, what would be the best way and how would I sort the teams based on elo ranking and add them to the new Arraylist.

Infiniti
  • 339
  • 1
  • 2
  • 7
  • Well, why don't you try something and see how it goes? There are a *lot* of sorting questions on SO, and I'm sure you'd be able to find something helpful without you needing someone to tell you exactly what to do. – awksp Jul 02 '14 at 22:58

1 Answers1

0

Here is one way:

class Scoring{

private ArrayList<Team> teams;



public void addTeams(ArrayList<Team> toAdd){

for(Team t : toAdd){
for(int i = 0; i < teams.size(); i++){
if(teams.get(i).elo<t.elo)break;
}
teams.add(i, t);
}

}

}

Another way to do this, would be to create a comparitor, and sort the arraylist toAdd using that comparitor, then adding it to teams.

Dean Leitersdorf
  • 1,303
  • 1
  • 11
  • 22