Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. static choice_t *
  2. stack_push(choice_t *stack, pset_t **grid)
  3. {
  4.   unsigned int i, j;
  5.   unsigned int i_choice, j_choice;
  6.   unsigned int min_card = grid_size+1;
  7.   char str[grid_size];
  8.   char str_choice[grid_size];
  9.  
  10.   choice_t *new_element = malloc(sizeof (choice_t));
  11.   if (new_element == NULL)
  12.     {
  13.       fprintf(output_file, "error : Out of memory!\n");
  14.     }
  15.  
  16.   new_element->grid = grid_copy(grid);
  17.  
  18.   // getting the minimal cardinality
  19.   for (i = 0; i < grid_size; i++)
  20.     {
  21.       for (j = 0; j < grid_size; j++)
  22.     {
  23.       if (pset_cardinality(grid[i][j]) < min_card
  24.           && (!pset_is_singleton(grid[i][j])) )
  25.         {
  26.           min_card = pset_cardinality(grid[i][j]);
  27.           i_choice = i;
  28.           j_choice = j;
  29.         }
  30.     }
  31.     }
  32.  
  33.  
  34.   pset2str(str, grid[i_choice][j_choice]);
  35.   pset2str(str_choice, pset_leftmost(grid[i_choice][j_choice]));
  36.   fprintf(output_file, "Cell : grid[%d][%d] = '%s', "
  37.       "choice = '%s' \n ", i_choice, j_choice, str, str_choice);
  38.   new_element->x = i_choice;
  39.   new_element->y = j_choice;
  40.   new_element->choice = pset_leftmost(grid[i_choice][j_choice]);
  41.   new_element->grid[i_choice][j_choice] =
  42.     pset_leftmost(grid[i_choice][j_choice]);
  43.  
  44.  
  45.   if (!grid_consistency(new_element->grid) )
  46.     {
  47.       return NULL;
  48.     }
  49.   new_element->previous = stack;
  50.  
  51.   return new_element;
  52.  
  53. }
Add Comment
Please, Sign In to add comment