//Recursive method for obtaining the winner of a tournament. //if you call this method with a tournament Node, you can obtain the winner of that Node in specific. public Player winnerTournament(TournamentNode actualNode) { if (actualNode.isSon()) return actualNode._player; else return winnerTournamentAux(actualNode._leftNode, actualNode._rightNode)._player; }
//Auxiliar method of winnerTournament used for the recursion of the method in both Nodes of the tree private TournamentNode winnerTournamentAux(TournamentNode tournamentNodeleft, TournamentNode tournamentNoderight) { //end statement, when the Nodes are Sons if (tournamentNodeleft.isSon()) return winnerMatch(tournamentNodeleft, tournamentNoderight); else { //Obtains the winner of the games in the left and right Nodes and obtains the champion TournamentNode leftwinner = winnerTournamentAux(tournamentNodeleft._leftNode, tournamentNodeleft._rightNode); TournamentNode rightwinner = winnerTournamentAux(tournamentNoderight._leftNode, tournamentNoderight._rightNode); return winnerTournamentAux(leftwinner, rightwinner); } }