CSC112 Spring 2016 Examples
#include <unistd.h>1#include <iostream>2#include <time.h>3#include <cstdlib>4#include <vector>5#include <sstream>6#include "swiss.h"78using namespace std;910class ContestInt : public SwissTournament<int>::Contestant {11public:12ContestInt() {13value = rand();14}1516virtual std::string name() {17ostringstream os;18os << value;19return os.str();20}212223virtual int *player() {24return &value;25}2627int value;28};293031int main()32{33SwissTournament<int> *tournament;34vector<SwissTournament<int>::Contestant *> players;35pair<SwissTournament<int>::Contestant*, SwissTournament<int>::Contestant*> p;36int n;3738cout << "How many? ";39cin >>n;40for(int i=0; i<n; i++) {41players.push_back(new ContestInt);42}4344srand(time(0));4546tournament = new SwissTournament<int>(players);4748while(!tournament->tournamentDone()) {49tournament->printPairings();50while(!tournament->roundDone()) {51p = tournament->getMatch();52ContestInt *c1 = (ContestInt*)p.first;53ContestInt *c2 = (ContestInt*)p.second;54if(c2 == nullptr or c1->value > c2->value)55tournament->report(c1);56else57tournament->report(c2);58}59tournament->printLeader();60tournament->nextRound();61sleep(5);62}6364return 0;65}6667