struct node *count_out( struct node *head, unsigned n ) { assert( head ); unsigned length = 1; struct node *prev = head, *next = head->next; while ( next != head ) { prev = next; next = next->next; ++ length; } while ( length > 1 ) { for ( unsigned m = n % length; m > 0; --m ) { prev = next; next = next->next; } next = next->next; prev->next = next; -- length; } assert( next->next == next ); return next; }