Dr. Dobb's Journal February 1997
/* schedule a pair 'pair_no', and then the others */ int schedule_pair(const int pair_no, const int i_start) { if( pair_no >= N_players/2 ) return TRUE; for(i=i_start; i<=N_players; i++) for(j=i+1; j<=N_players; j++) { int ti = Sorted_indices[i], tj = Sorted_indices[j]; if( allo[ti] == 0 && allo[tj] == 0 && Has_played[ti][tj] == 0 ) { /* Try pairing ti and tj */ allo[ti] = tj; allo[tj] = ti; if(schedule_pair(pair_no+1,i+1)) return TRUE; /* It worked! */ else allo[ti] = allo[tj] = 0; /* It didn't work. */ } } return FALSE; /* No valid pairing was found */ }