Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static choice_t *
- stack_push(choice_t *stack, pset_t **grid)
- {
- unsigned int i, j;
- unsigned int i_choice, j_choice;
- unsigned int min_card = grid_size+1;
- char str[grid_size];
- char str_choice[grid_size];
- choice_t *new_element = malloc(sizeof (choice_t));
- if (new_element == NULL)
- {
- fprintf(output_file, "error : Out of memory!\n");
- }
- new_element->grid = grid_copy(grid);
- // getting the minimal cardinality
- for (i = 0; i < grid_size; i++)
- {
- for (j = 0; j < grid_size; j++)
- {
- if (pset_cardinality(grid[i][j]) < min_card
- && (!pset_is_singleton(grid[i][j])) )
- {
- min_card = pset_cardinality(grid[i][j]);
- i_choice = i;
- j_choice = j;
- }
- }
- }
- pset2str(str, grid[i_choice][j_choice]);
- pset2str(str_choice, pset_leftmost(grid[i_choice][j_choice]));
- fprintf(output_file, "Cell : grid[%d][%d] = '%s', "
- "choice = '%s' \n ", i_choice, j_choice, str, str_choice);
- new_element->x = i_choice;
- new_element->y = j_choice;
- new_element->choice = pset_leftmost(grid[i_choice][j_choice]);
- new_element->grid[i_choice][j_choice] =
- pset_leftmost(grid[i_choice][j_choice]);
- if (!grid_consistency(new_element->grid) )
- {
- return NULL;
- }
- new_element->previous = stack;
- return new_element;
- }
Add Comment
Please, Sign In to add comment