private int search ( List < Node < ColumnName > > partial , SolutionAcceptor < ColumnName > output ) { int results = 0 ; if ( head . right == head ) { List < List < ColumnName >> result = new ArrayList < List < ColumnName > > ( partial . size ( ) ) ; for ( Node < ColumnName > row : partial ) { result . add ( getRowName ( row ) ) ; } output . solution ( result ) ; results += 1 ; } else { ColumnHeader < ColumnName > col = findBestColumn ( ) ; if ( col . size > 0 ) { coverColumn ( col ) ; Node < ColumnName > row = col . down ; while ( row != col ) { partial . add ( row ) ; Node < ColumnName > node = row . right ; while ( node != row ) { coverColumn ( node . head ) ; node = node . right ; } results += search ( partial , output ) ; partial . remove ( partial . size ( ) - 1 ) ; node = row . left ; while ( node != row ) { uncoverColumn ( node . head ) ; node = node . left ; } row = row . down ; } uncoverColumn ( col ) ; } } return results ; }
Find a solution to the problem .