誰が最も多くのゲームに勝ったかという順序で、「名前」(以下)の配列でチームをランク付けする必要があります。2つのチームが同じ量のゲームに勝った場合、それらを打ち負かしたチームの勝利を比較する必要があります。私がこれまでに持っているコードは以下の通りです。
完全な問題の説明はここにあります:http ://www.cs.duke.edu/csed/newapt/tournamentrank.html
そのため、コンパレータを再帰的に使用したいと思います。コンパレータはどのようにして元のデータにアクセスできますか?勝ったチームの同じクラスの変数を受け取るTeamクラスを作成しようとしましたが、それは明らかに機能しません。ここで立ち往生、助けてください!
public class TournamentRanker implements Comparator<String>{
public class Team {
    String name;
    Integer wins;
    Team beatEm;
}
        //HOW TO make maps visible to comparator?
         public String[] rankTeams(String[] names, String[] lostTo) { 
             //map all teams to number of wins & to team that beat them
             ArrayList<String> teams = new ArrayList<String>();
             HashMap<String, Integer> Teamwins = new HashMap<String, Integer>();
                HashMap<String, String> Whobeat = new HashMap<String, String>();
             for(int x=0; x<names.length; x++)
             {
                 if(!teams.contains(names[x]))
                     teams.add(names[x]);
                 if(!Teamwins.containsKey(names[x]))
                     Teamwins.put(names[x], 0);
                 Whobeat.put(names[x],  lostTo[x]);
                 if(!Teamwins.containsKey(lostTo[x]) && !lostTo[x].equals(""))
                     Teamwins.put(lostTo[x], 0);
                 if(!lostTo[x].equals(""))
                     Teamwins.put(lostTo[x], (Teamwins.get(lostTo[x])+1));
             }
             for(String s: names)
             {
                 Integer wins = Teamwins.get(s);
                 Team beatEm = new Team(Whobeat.get(s), Teamwins.get(Whobeat.get(s)), ????)
             }
             //SORT list & turn into ARRAY
             Comparator<String> comp = new TournamentRanker();
             Collections.sort(teams, comp);
             String [] sortedTeams = new String[teams.size()];
             return teams.toArray(sortedTeams);
         }
        //NEED to use compareTo***?? OTHER strategy????
        //USE COMPARTOR - how to access all the data?
        public int compare(String team1, String team2){
        }       
 }