I want to create a round robin tournament. The function receive a list (I've used a deque) and for now just prints to stdout the results (e.g. the round number and the schedule). If I wanted to provide the user a data structure that has all the miningful informations, what do you propose?
Here my code (I'm a C++ novice):
#include <iostream> #include <deque>
int main(void) { // games per team: n - 1 std::deque<int> tournament; int c; int first = 0; // simple example with integers for (int i = 1; i < 8; i++) { tournament.push_back(i); } bool even = !(tournament.size() & 1); if (even) { first = tournament.front(); tournament.pop_front(); } for (int j = 0; j < tournament.size() - 1; j++) { std::cout << "Round " << j + 1 << ":" << std::endl; if (even) { std::cout << first << " vs " << tournament.back() << std::endl; } for (int i = 0; i < tournament.size()/2; i++) { std::cout << tournament[i] << " vs " << tournament [tournament.size() - i - 2] << std::endl; } tournament.push_front(tournament.back()); tournament.pop_back(); } c = getchar(); return 0;
mattia wrote: > I want to create a round robin tournament. The function receive a list > (I've used a deque) and for now just prints to stdout the results (e.g. > the round number and the schedule). If I wanted to provide the user a > data structure that has all the miningful informations, what do you > propose?
Il Sat, 07 Nov 2009 18:24:03 -0600, red floyd ha scritto:
> mattia wrote: >> I want to create a round robin tournament. The function receive a list >> (I've used a deque) and for now just prints to stdout the results (e.g. >> the round number and the schedule). If I wanted to provide the user a >> data structure that has all the miningful informations, what do you >> propose?
Well, I'm sorry you've misunderstood but I was asking for an advice, not for homework (that I don't have since a long time ago). I've also said that I'm a c++ novice, so I wated to know more about the OO programming facing a simple problem that I was trying to solve.
mattia wrote: > Il Sat, 07 Nov 2009 18:24:03 -0600, red floyd ha scritto:
>> mattia wrote: >>> I want to create a round robin tournament. The function receive a list >>> (I've used a deque) and for now just prints to stdout the results (e.g. >>> the round number and the schedule). If I wanted to provide the user a >>> data structure that has all the miningful informations, what do you >>> propose?
> Well, I'm sorry you've misunderstood but I was asking for an advice, not > for homework (that I don't have since a long time ago). I've also said > that I'm a c++ novice, so I wated to know more about the OO programming > facing a simple problem that I was trying to solve.
Sorry. Then you're better off asking in comp.algorithms. There's nothing C++ specific in your question, other than your use of a deque.
> mattia wrote: >> Il Sat, 07 Nov 2009 18:24:03 -0600, red floyd ha scritto:
>>> mattia wrote: >>>> I want to create a round robin tournament. The function receive a >>>> list (I've used a deque) and for now just prints to stdout the >>>> results (e.g. the round number and the schedule). If I wanted to >>>> provide the user a data structure that has all the miningful >>>> informations, what do you propose?
>> Well, I'm sorry you've misunderstood but I was asking for an advice, >> not for homework (that I don't have since a long time ago). I've also >> said that I'm a c++ novice, so I wated to know more about the OO >> programming facing a simple problem that I was trying to solve.
> Sorry. Then you're better off asking in comp.algorithms. There's > nothing C++ specific in your question, other than your use of a deque.