コード例 #1
0
ファイル: remove_ring.c プロジェクト: MrQ007/tomopy
void bubble_2_arrays(
	float* median_array, int* position_array, int index,
	int length)
{
	if(index > 0 && index < length -1){
		if(median_array[index] < median_array[index-1]){
			swap_float(median_array, index, index-1);
			swap_integer(position_array, index, index-1);
			bubble_2_arrays(median_array, position_array, index-1, length);
		}else if(median_array[index] > median_array[index+1]){
			swap_float(median_array, index, index+1);
			swap_integer(position_array, index, index+1);
			bubble_2_arrays(median_array, position_array, index+1, length);
		}
	}else if(index == 0){
		if(median_array[index] > median_array[index+1]){
			swap_float(median_array, index, index+1);
			swap_integer(position_array, index, index+1);
			bubble_2_arrays(median_array, position_array, index+1, length);
		}
	}else if(index == length -1){
		 if(median_array[index] < median_array[index-1]){
			swap_float(median_array, index, index-1);
			swap_integer(position_array, index, index-1);
			bubble_2_arrays(median_array, position_array, index-1, length);
		}
	}
	return;
}
コード例 #2
0
ファイル: remove_ring.c プロジェクト: MrQ007/tomopy
int partition_2_arrays(
	float* median_array, int* position_array, int left,
    int right, int pivot_index)
{
	float pivot_value = median_array[pivot_index];
	swap_float(median_array, pivot_index, right);
	swap_integer(position_array, pivot_index, right);
	int store_index = left;
	for(int i=left; i < right; i++){
		if(median_array[i] <= pivot_value){
			swap_float(median_array, i, store_index);
			swap_integer(position_array, i, store_index);
			store_index +=1;
		}
	}
	swap_float(median_array, store_index, right);
	swap_integer(position_array, store_index, right);
	return store_index;
}
コード例 #3
0
ファイル: load_file.c プロジェクト: MarcBrout/Corewar
int		check_header(int fd, t_header *head)
{
  int		ret;
  int		size;
  char		c;

  if ((ret = read(fd, head, sizeof(t_header)) <
       (int)sizeof(t_header)))
    return (1);
  if (g_endian)
    {
      head->magic = swap_integer(head->magic);
      head->prog_size = swap_integer(head->prog_size);
    }
  if (head->magic != COREWAR_EXEC_MAGIC)
    return (2);
  size = 0;
  while ((ret = read(fd, &c, 1)))
    size += 1;
  if (size != head->prog_size)
    return (1);
  return (0);
}