logo CodeStepByStep logo


Language/Type: C++ graphs collections
Related Links:
Author: Marty Stepp (on 11/14)

Write a function tournamentWinners that accepts a reference to a BasicGraph representing a tournament and returns a Set of Vertex* representing all the winners in that tournament. A tournament is a graph of a contest among n players. Each player plays a game against each other player, and either wins or loses it (no draws). A player is represented by a node, and a directed edge shows the winner pointing to the loser. In the tournament shown below, player A won against player E, but lost against players B, C, and D.


A tournament winner is a player who, for each other player, either won a game against that player, or won a game against a player who won their game against that player (or both). For example, in the graph above, players B, C, and E are tournament winners. However, player D is not a tournament winner, because he neither beat player C, nor beat anyone who in turn beat player C. Although player D won against player E, who in turn won against player B, who then won against player C, under our definition player D is not a winner.

You may assume that the parameter values passed are valid.

Type your C++ solution code here:

This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.