generate all possible triplets
for ( ptr1 = head ; ptr1 != NULL ; ptr1 = ptr1 -> next ) for ( ptr2 = ptr1 -> next ; ptr2 != NULL ; ptr2 = ptr2 -> next ) for ( ptr3 = ptr2 -> next ; ptr3 != NULL ; ptr3 = ptr3 -> next )