Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 2.63 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void *verifySudoku(void*ptr) {
  2.          int i,j,sA[S];
  3.          int  temp = 0;
  4.          struct sudoku *data;
  5.          data = (struct sudoku *)ptr;
  6.          for(i=0;i < S; i++){
  7.                  sA[i]=data->array[i];
  8.                  printf("%d", sA[i]);
  9.          }
  10.  
  11.         for(j=0; j<S;j++){
  12.          for(i=0; i<S-1;i++){
  13.                  if(sA[i+1] < sA[i]){
  14.                         temp=sA[i];
  15.                         sA[i] = sA[i+1];
  16.                         sA[i+1]=temp;
  17.                 }
  18.          }
  19.        }
  20.         //Compare
  21.         i=0;
  22.         while (i<9)
  23.         {
  24.                 if( sA[i]!=0 ) {
  25.  
  26.                         if(sA[i] == sA[i+1])
  27.                         {
  28.                           *(data->is_valid) = -1;
  29.  
  30.                         }else{
  31.                                 i++;
  32.                         }
  33.  
  34.                 }else{
  35.                         i++;
  36.                 }
  37.         }
  38.         //Thread validated, close.
  39.         pthread_exit(0);
  40. }
  41.  
  42. int main (){
  43.         //loop program
  44.         int board[S][S];
  45.         //Valid 1= valid 0 =p not
  46.         int is_valid=1;
  47.         int z=0,z1,i,r=0,c,n;
  48.         pthread_t t_id[3*S];
  49.         int t_ind =0;
  50.  
  51.         //User Prompt
  52.         char buffer[10];
  53.         printf("Please enter a file name?");
  54.         scanf("%s", buffer);
  55.  
  56.  
  57.         read_sudoku(buffer, board);
  58.         printf("Row into Structure:\n");
  59.         //Rows -> Struct
  60.         for (z = 0; z < S; z++)
  61.         {
  62.           struct sudoku *row = (struct sudoku *) malloc(sizeof(struct sudoku));
  63.                 for (r = 0; r < S; r++)
  64.                 {
  65.                         //printf("%d",r);
  66.                         row->array[r] = board[r][z];
  67.                         //printf("%d",row->array[r]);
  68.                 }
  69.           row->is_valid = &is_valid;
  70.           pthread_create(&(t_id[t_ind++]),NULL,verifySudoku, (void *) row);
  71.         }
  72. /*
  73.         for (z1=0; z1 < S; z1++)
  74.         {
  75.           struct sudoku *col = (struct sudoku *) malloc(sizeof(struct sudoku));
  76.                 for (c =0; c < S; c++)
  77.                 {
  78.                         col->array[c] = board[z1][c];
  79.                         printf("%d", col->array[c]);
  80.  
  81.                 }
  82.           col->is_valid = &is_valid;
  83.           pthread_create(&(t_id[t_ind++]), NULL, verifySudoku, (void *) col);
  84.         }
  85. */
  86.         //Handle Blocks
  87.  
  88.         //Wait
  89.  
  90.                 //3*S for gird included 2*S for row/col ver
  91.                 for(i=0; i<18;i++){
  92.                   pthread_join( t_id[i], NULL);
  93.                 }
  94.  
  95.  
  96.         if(is_valid ==-1){
  97.         printf("Invalid\n");
  98.         }
  99.         exit(0);
  100.  
  101. }