Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:13:27+00:00 2026-06-08T23:13:27+00:00

I have to rank the teams in the array names (below) in order of

  • 0

I have to rank the teams in the array “names” (below) in order of who won the most games. If two teams won the same amount of games then I have to compare the wins of the teams that beat them. The code I have so far is below.

The full problem statement is given here: http://www.cs.duke.edu/csed/newapt/tournamentrank.html

So I want to use the comparator recursively. How can the Comparator can have access to the original data? I tried creating a Team class that takes a variable of the same class for the team that beat it, but that clearly doesn’t work. Stuck here, please help!

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){


        }       

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:13:29+00:00Added an answer on June 8, 2026 at 11:13 pm

    To make the maps visible, I suggest making the Comparator an inner class of TournamentRanker, and making the maps instance members of the TournamentRanker class, as follows:

    public class TournamentRanker {
    
        public class Team {
            String name;
            Integer wins;
            Team beatEm;
        }
    
        // 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>();
    
        public String[] rankTeams(String[] names, String[] lostTo) { 
            TeamComparator teamComparator = new TeamComparator();
    
            // Use teamComparator to sort teams.
            ...
        }
    
        private TeamComparator implements Comparator<String> {
            public int compare(String team1, String team2){
                // This function can now access the maps.
    
                // Perform the comparison here.
                ...
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: teams ---------------- |uid|name |rank| ---------------- | 1 |Team1| 1 |
I have a order list and I want to generate and rank the product
I have two dictionaries in Python. One is a list of teams and their
I have a query that creates a result set like this: Rank Name 1
I have an object in a list that I need to rank several different
I have these tables: comments uid id pid pages pid user users id rank
Suppose i have a mysql table name table with fields rank date id The
I have a table in SQLite database of Android which has a column RANK
I have the following query so far, which works perfectly to rank the books
I have read the explanation in http://en.wikipedia.org/wiki/PageRank and i understand that the page rank

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.