コード例 #1
0
ファイル: simpleList.c プロジェクト: trejoel/Ch03
int main(void) {
	int num = 0;
	int input = 1;
	int retval = 0;
	//struct NODE *llist;
	miNodo *llist;
	

	llist = (struct NODE *)malloc(sizeof(struct NODE));
	llist->number = 0;
	llist->next = NULL;
	
	while(input != 0) {
		printf("\n-- Menu Selection --\n");
		printf("0) Quit\n");
		printf("1) Insert\n");
		printf("2) Delete\n");
		printf("3) Search\n");
		printf("4) Display\n");
		scanf("%d", &input);
		
		switch(input) {
			case 0: 
			default:
				printf("Goodbye ...\n");
				input = 0;
				break;
			case 1:
				printf("Your choice: `Insertion'\n");
				printf("Enter the value which should be inserted: ");
				scanf("%d", &num);
				append_node(llist, num);
				break;
			case 2:
				printf("Your choice: `Deletion'\n");
				printf("Enter the value which should be deleted: ");
				scanf("%d", &num);
				delete_node(llist, num);
				break;
			case 3:
				printf("Your choice: `Search'\n");
				printf("Enter the value you want to find: ");
				scanf("%d", &num);
				if((retval = search_value(llist, num)) == -1)
					printf("Value `%d' not found\n", num);
				else
					printf("Value `%d' located at position `%d'\n", num, retval);
				break;
			case 4:
				printf("You choice: `Display'\n");
				display_list(llist);
				break;
		} /* switch */
	} /* while */
	
	free(llist);
	return(0);
}
コード例 #2
0
ファイル: hotrace.c プロジェクト: Succubae/42
void	get_values(t_ascii *root)
{
	char	*line;

	while (get_next_line(0, &line) > 0)
	{
		search_value(root, line);
	}
}
コード例 #3
0
int main(void) {
 //num and input are changed to character variables.
 char num;
 char input = 'I';
 int retval = 0;
 struct NODE *llist;
   
 //Altered llist to use letter instead of num.  The variable is not initialized.
 llist = (struct NODE *)malloc(sizeof(struct NODE));
 llist->letter;
 llist->next = NULL;
   
 while(input != 'Q') {
  /* Alter menu to use characters instead of numbers. 
   * scanf is changed to record string instead of integer
   */
  printf("\n-- Menu Selection --\n");
  printf("Q) Quit\n");
  printf("I) Insert\n");
  printf("D) Delete\n");
  printf("S) Search\n");
  printf("P) Display\n");
  scanf("%s", &input);


  //Switch has been altered to check for character input instead of integer input
  switch(input) {
   case 'Q': 
   default:
    printf("Goodbye ...\n");
    input = 'Q';
    break;
   case 'I':
    printf("Your choice: `Insertion'\n");
    printf("Enter the value which should be inserted: ");
    scanf("%s", &num);
    append_node(llist, num);
    break;
   case 'D':
    printf("Your choice: `Deletion'\n");
    printf("Enter the value which should be deleted: ");
    scanf("%s", &num);
    delete_node(llist, num);
    break;
   case 'S':
    printf("Your choice: `Search'\n");
    printf("Enter the value you want to find: ");
    scanf("%s", &num);
    if((retval = search_value(llist, num)) == -1)
     printf("Value `%s' not found\n", &num);
    else
     printf("Value `%s' located at position `%d'\n", &num, retval);
    break;
   case 'P':
    printf("You choice: `Display'\n");
    display_list(llist);
    break;
   } /* switch */
  } /* while */

 free(llist);
 return(0);
}
コード例 #4
0
ファイル: random.c プロジェクト: GuillaumeFuchs/Ensimag
/**
 * Set the dimension of the state space for a PNL_QMC rng
 *
 * @param rng a PnlRng
 * @param dim the dimension of the state space
 * @return OK or FAIL
 */
int pnl_rng_sdim (PnlRng *rng, int dim)
{
  rng->counter=1;
  rng->has_gauss=0;
  rng->gauss=0.;
  rng->dimension = dim;
  if ( dim < 1 ) return FAIL;
  switch (rng->type)
    {
      case PNL_RNG_SQRT:
      {
        int i;
        sqrt_state *state;
        if ( dim > PNL_DIM_MAX_QMC ) return FAIL;
        state = (sqrt_state *)(rng->state);
        prime_number(rng->dimension, state->prime);
        for(i=0; i<rng->dimension; i++)
          {
            state->alpha[i]= sqrt((double) state->prime[i]);
          }
      }
      break;
      case PNL_RNG_HALTON:
        if ( dim > PNL_DIM_MAX_QMC ) return FAIL;
        prime_number(rng->dimension, ((halton_state *)(rng->state))->prime);
        break;
      case PNL_RNG_FAURE:
      {
        int prime[PNL_DIM_MAX_QMC];
        faure_state *state;
        if ( dim > DIM_MAX_FAURE ) return FAIL;
        state = (faure_state *)(rng->state);
        binomial(FAURE_MAXI);
        if((rng->dimension == 2)||(rng->dimension == 1))
          state->r= 3;
        else
          {
            prime_number(rng->dimension, prime);
            state->r=search_value(rng->dimension,prime,rng->dimension);
          }
      }
      break;
      case PNL_RNG_NIEDERREITER:
      {
        int i, j;
        nied_state *state;
        if ( dim  > PNL_DIM_MAX_NIED ) return FAIL;
        state = (nied_state *)(rng->state);
        /* Initialization of initX_n[] */
        for (i=1; i<=PNL_DIM_MAX_NIED; i++)
          state->initialX_n[i]= 0;

        state->facteur= 1.0/(double)(1UL << (BIT_MAX_NIED+1));
        state->saut = 1L << 12;
        state->initial_d = state->saut;

        /* Gray code of saut */
        state->gray = state->saut^(state->saut >> 1);
        for (i=0; i<=BIT_MAX_NIED; i++)
          {
            if (state->gray == 0)
              break;
            for (j= 1; j<= PNL_DIM_MAX_NIED; j++)
              {
                if ((state->gray & 1) == 0)
                  break;
                /* XOR sum */
                state->initialX_n[j] ^= NiedC[i][j];

              }
            state->gray >>= 1;
          }
      }
      break;
      case PNL_RNG_SOBOL_I4:
        if ( dim  > PNL_SOBOL_I4_DIM_MAX2) return FAIL;
        i4_sobol_init (rng, dim);
      break;
      case PNL_RNG_SOBOL_I8:
        if ( dim  > PNL_SOBOL_I8_DIM_MAX2) return FAIL;
        i8_sobol_init (rng, dim);
      break;
      
      default:
        printf ("For PNL_MC rng, you shoud use pnl_rng_sseed instead of pnl_rng_sdim\n");
      break;
    }
  return OK;
}
コード例 #5
0
ファイル: spatial_query.hpp プロジェクト: 7modelsan/kbengine
 void increment()
 {
     ++m_current;
     search_value();
 }
コード例 #6
0
ファイル: spatial_query.hpp プロジェクト: 7modelsan/kbengine
 void initialize(node_pointer root)
 {
     rtree::apply_visitor(*this, *root);
     search_value();
 }
コード例 #7
0
ファイル: spot_find.c プロジェクト: paul-nunez/hypersoft
float *find_spot(float *pixel, int n, float threshold, float replace, struct spot_params *params, struct image *img){

  int flag=0;
  int num = 0;
  int input = 1;
  int retval = 0;
  struct NODE *llist;
  
  llist = (struct NODE *)malloc(sizeof(struct NODE));
  llist->number = 0;
  llist->j=0;
  llist->next = NULL;
  
  //Find the first pixel in spot
  params->brightness=0;
  params->xcm=0;
  params->ycm=0;
  params->counter=0;
  int i=(int)sqrt(n)+2;  
  //int i=(int)sqrt(n);  
  //printf("N %d\n", i);
  while(flag==0){
    if(pixel[i]>=threshold){
      //fprintf(stderr, "Pixel value = %f\n", pixel[i]);
      add_to_params(i, pixel[i], params, img); //Aids in brightness and cm calculation
      pixel[i]=replace;
      num=1;
      llist->head=num;
      append_node(llist, num, i);   
      flag=1;
      //fprintf(stderr, "%d %lf %lf", i, pixel[i], pixel[i+1]);
      //frintf(stderr, "\nFound spot at j=%d (replacement = %f)\n", i-1, replace);
    }  
    if(i==n-1){
      fprintf(stderr, "\nNo spot found\n");
      params->brightness=-1.0;
      flag=1;
    }

    i++;    

  }


  //Now start adding nodes as long as neighbors meet threshold
  flag=0;
  int j=i;

  if(i==n){
    flag=1; //No spot found
  }

  while(flag==0){ //Flag will be 1 when list is done
    j=search_value(llist, llist->head); //Search for head of list
    //j=num; //CHANGE
    
    //Now search all of it's neighbors to see if we need to add elements to the list
    if(pixel[j]>=threshold){
      add_to_params(j, pixel[j], params, img); //Aids in brightness and cm calculation
      num++; 
      llist->head=num;
      //num++; 
      pixel[j]=replace; 
      flag=1;
    }    
    if(pixel[j+1]>=threshold){
      add_to_params(j+1, pixel[j+1], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j+1); 
      pixel[j+1]=replace; 
      flag=1;
    }
    if(pixel[j-1]>=threshold){
      add_to_params(j-1, pixel[j-1], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j-1); 
      pixel[j-1]=replace; 
      flag=1;
    }
    if(pixel[j+(int)sqrt(n)-1]>=threshold){ 
      add_to_params(j+(int)sqrt(n)-1, pixel[j+(int)sqrt(n)-1], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j+(int)sqrt(n)-1); 
      pixel[j+(int)sqrt(n)-1]=replace; 
      flag=1;
    }
    if(pixel[j+(int)sqrt(n)]>=threshold){ 
      add_to_params(j+(int)sqrt(n), pixel[j+(int)sqrt(n)], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j+(int)sqrt(n)); 
      pixel[j+(int)sqrt(n)]=replace; 
      flag=1;
    }
    if(pixel[j+(int)sqrt(n)+1]>=threshold){ 
      add_to_params(j+(int)sqrt(n)+1, pixel[j+(int)sqrt(n)+1], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j+(int)sqrt(n)+1); 
      pixel[j+(int)sqrt(n)+1]=replace; 
      flag=1;
    }
    if(pixel[j-(int)sqrt(n)-1]>=threshold && j-(int)sqrt(n)-1>=0){ //CHANGE oct 31 2012
      add_to_params(j-(int)sqrt(n)-1, pixel[j-(int)sqrt(n)-1], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j-(int)sqrt(n)-1); 
      pixel[j-(int)sqrt(n)-1]=replace; 
      flag=1;
    }
    if(pixel[j-(int)sqrt(n)]>=threshold){ 
      add_to_params(j-(int)sqrt(n), pixel[j-(int)sqrt(n)], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j-(int)sqrt(n)); 
      pixel[j-(int)sqrt(n)]=replace; 
      flag=1;
    }
    if(pixel[j-(int)sqrt(n)+1]>=threshold){ 
      add_to_params(j-(int)sqrt(n)+1, pixel[j-(int)sqrt(n)+1], params, img);
      num++; 
      llist->tail=num;
      append_node(llist, num, j-(int)sqrt(n)+1); 
      pixel[j-(int)sqrt(n)+1]=replace; 
      flag=1;
    }
    if(num==1){ //If there is only one pixel that meets threshold, the loop should stop
      llist->head=llist->tail;
      flag=1;
    }
    if(flag==1){
      delete_node(llist, llist->head); //Delete node whose neighbors have already been checked
    }

    flag=0;

    if(llist->head==llist->tail) flag=1;        //Done with list
    if(llist->head!=llist->tail) llist->head++; //go to next item on list
    
    //fprintf(stderr, "(%d, %d), ", llist->head, llist->tail);

  }

  /*
  FILE *mod;
  mod=fopen("modified_image.txt", "w");
  for(int k=0; k<n; k++){    
    int l=k%(int)sqrt(n);
    int m=(int)k/sqrt(n);
    fprintf(mod, "%d  %d  %f\n", l, m, pixel[k]);
    if(l==sqrt(n)-1) fprintf(mod, "\n");
  }
  fclose(mod);
  */
  float step=img->x[1]-img->x[0];
  params->xcm=params->xcm/params->brightness;
  params->ycm=params->ycm/params->brightness;
  params->radius=sqrt(params->counter*step*step/PI);
  //fprintf(stderr, "brightness = %f\nxcm = %f\nycm = %f\nradius = %f\n", params->brightness, params->xcm, params->ycm, params->radius);

  return pixel;

}