the source of the article:https://github.com/Fibird/Round-robin-schedule
#include <iostream>
#include <math.h>
#define N 3
using namespace std;
int main()
{
int sche = pow(2.0, N); //the number of athlete
int **arr = new int*[sche];
int bw = 1;
for(int i=0; i<sche; i++)
{
arr[i] = new int[sche];
}
int bid; //the id of block
int c_offset, r_offset;
//init line 1 with 1 to 8
for(int i=0; i<sche; i++)
arr[0][i] = i + 1;
for(int j=0; j<N; j++)
{
for(int r=0; r<bw; r++)
{
for(int c=0; c<sche; c++)
{
bid = (c + bw) / bw;
c_offset = pow(-1.0, bid+1) * bw; //move to right or move to left bw location
r_offset = bw;
arr[r + r_offset][c + c_offset] = arr[r][c];
}
}
bw = bw * 2; //every loop the problem will double
}
// outputs the schedule of the round robin
cout << "N/D";
for(int i=1; i<sche; i++)
cout << "\t" << i;
cout << endl;
for(int i=0; i<sche; i++)
{
cout << arr[i][0];
for(int j=1; j<sche; j++)
{
cout << "\t" << arr[i][j];
}
cout << endl;
}
//free memory
for(int i=0; i<sche; i++)
delete arr[i];
delete arr;
return 0;
}