Beispiel #1
0
int main(void) {
 int array[MAXARRAY] = {0};
 int i = 0;

 /* load some random values into the array */
 for(i = 0; i < MAXARRAY; i++)
  array[i] = rand() % 100; 

 /* print the original array */
 printf("Before shellsort: ");
 for(i = 0; i < MAXARRAY; i++) {
  printf(" %d ", array[i]); 
 }
 printf("\n");

 shellsort(array, MAXARRAY, 1);

 /* print the `shellsorted' array */
 printf("After  shellsort: ");
 for(i = 0; i < MAXARRAY; i++) {
  printf(" %d ", array[i]); 
 }
 printf("\n");
 getch();
 return 0;
}
Beispiel #2
0
int main(void)
{
	int v[] = {0,9,8,7,6,5,4,3,2,1,10};
	shellsort(v, NELEMS(v));
	printarr(v, NELEMS(v));
	return 0;
}
Beispiel #3
0
void graph_out_dimacs(FILE *out, graph_t *g)
{
    index_t n = g->num_vertices;
    index_t m = g->num_edges;
    index_t *e = g->edges;
    index_t *c = g->colors;
    fprintf(out, "p motif %ld %ld\n", (long) n, (long) m);
    for(index_t i = 0; i < m; i++)
        fprintf(out, "e %ld %ld\n", (long) e[2*i+0]+1, (long) e[2*i+1]+1);
    for(index_t i = 0; i < n; i++)
        fprintf(out, "n %ld %ld\n", (long) i+1, (long) c[i]+1);
    if(g->has_target) {
        fprintf(out, "k %ld", g->motif_size);
        index_t s = graph_max_color(g) + 1;
        for(index_t i = 0; i < s; i++) {
            for(index_t j = 0; j < g->motif_counts[i]; j++)
                fprintf(out, " %ld", i+1);
        }
        fprintf(out, "\n");
        fprintf(out, "t unique ");
        index_t k = g->motif_size;
        shellsort(k, g->target);
        for(index_t j = 0; j < k; j++) {
            fprintf(out, "%ld%s", g->target[j]+1, j == k-1 ? "\n" : " ");
        }
    }
}
Beispiel #4
0
main ()
{
	int n, i;
	char s[] = "3307";
	int v[] = {2, 9, 4, 7, 6, 7, 5, 8, 3, 1};
	
	//문자열을 숫자로 변환
	n = atoi (s);
	printf("n = %d\n", n);

	//문자열 앞뒤 순서바꿈
	reverse (s);
	printf("s = %s\n", s);

	//배열의 크기(요소개수)
	printf("shell sorting\n");
	n = sizeof(v) / sizeof(v[0]);
	shellsort (v, n);
	for (i = 0; i < n; i++)
		printf("%d ", v[i]);
	printf("\n");	

	printf("\nPress any key to end...");
	getchar();
}
Beispiel #5
0
/*
 *int main(int argc, char* argv[]):
 ************************************
 *First round of error checking for correct program arguments.
 */
int main(int argc, char* argv[]){


	std::cout << "number of args =" << argc << std::endl;

        std::string addressFile="";

	/*
	 * If the program is ran without sufficient arguments it Will exit gracefully
	 * with suggestions for the usage of the program.

	 if (argc < 2) {
                 std::cerr << "Address File not Found\n";
                 std::cerr << "Usage:  " << argv[0] << " filename.txt" << std::endl;
	    return -1;
	  }
	 */


        std::vector<int> nums;
        
        for ( unsigned i = 999; i > 0; i--)
                nums.push_back(i);
        shellsort(nums);
        std::cout << "Vector after Shell Sort"<<std::endl;
        std::vector<int>::iterator it;
        for ( it = nums.begin() ; it != nums.end(); ++it)
                std::cout << ' ' << *it;
        std::cout << "\nDone Sorting"<< std::endl;
         

         return 0;
}
Beispiel #6
0
void calculate_and_sort_chi2(){
	int massCut = Settings.haloes_over_threshold;
	int nBins = NFW.bins;
	double vir = Cosmo.virial; 
	double *a_x; double *a_y; double v;
	double cc, mm, rr, rho0, rs, r_back;
	int n=0; int i=0; int k=0;
	int *vir_haloes; int n_vir=0;

	for(k=0; k<massCut; k++){
	v=haloes[k].th_vir;
	if(sqrt(v*v)<vir) n_vir++;
	}

fprintf(stderr, "Total of %d virialized haloes over %d. \n", n_vir, massCut);
	vir_haloes=(int*) calloc(n_vir, sizeof(int));

	for(k=0; k<massCut; k++){
	v=haloes[k].th_vir;
	if(sqrt(v*v)<vir) {
	vir_haloes[i]=k; i++;
	}
	}
	
//for(k=0; k<haloes[0].n_bins; k++)fprintf(stderr, "r:%lf, rho:%lf \n", haloes[0].radius[k], haloes[0].rho[k]);

Chi2.chi2s = (double*) calloc(n_vir, sizeof(double));
fit_and_store_nfw_parameters_from_list(n_vir, vir_haloes, massCut);

i=0;
for(k=0; k<n_vir; k++){
i=vir_haloes[k];
Chi2.chi2s[k] = haloes[i].chi_nfw;
//fprintf(stderr, "%d) chi2:%lf \n", k, Chi2.chi2s[k]);
}
i=0; 
k=0;

Chi2.chi2s = shellsort(Chi2.chi2s, n_vir);
Chi2.bins = nBins;
Chi2.binned_chi = (double*) calloc(Chi2.bins, sizeof(double));
Chi2.outcomes = (int*) calloc(Chi2.bins, sizeof(int));
Chi2.binned_chi = lin_stepper(Chi2.chi2s[0], Chi2.chi2s[massCut-1], nBins);

FILE *nfwfit = fopen(Urls_internal.output_prefix, "w");
//FILE *nfwfit = fopen("nfw_chi_2_distribution-vdez0_1.dat", "w");
//for(n=0; n<massCut; n++) fprintf(stderr, "%d, chi: %lf \n", n, Chi2.chi2s[n]);
fprintf(stderr, "\nBinning chi2...");
i=0; n=0; k=0;

Chi2.outcomes = lin_bin(Chi2.chi2s, Chi2.binned_chi, Chi2.bins, n_vir, Chi2.outcomes);
fprintf(stderr, "Binned.\n");

for(n=0; n<Chi2.bins; n++) {
fprintf(nfwfit, "%lf %d %lf\n", Chi2.binned_chi[n], Chi2.outcomes[Chi2.bins-n-1], (double) Chi2.outcomes[Chi2.bins-n-1]/(double)massCut);
//fprintf(stderr, "%lf %d %lf\n", 0, 0, 0); //Chi2.binned_chi[n], 0, 0); //Chi2.outcomes[Chi2.bins-n-1], (double) Chi2.outcomes[Chi2.bins-n-1]/(double)massCut);
}
fprintf(stderr, "Done.\n");
fclose(nfwfit);
}
Beispiel #7
0
int main() {
	int i;
	int v[] = {1, 4, 2, 0, 23, 1, 8, 9};
	shellsort(v, 8);
	for (i = 0; i < 8; i++)
		printf("%d ", v[i]);
}
int main() {

    read();
    shellsort();
    write();

    return(0); 
}
Beispiel #9
0
int main() {
    int v[] = {3,4,1,7,4,1,9,0,2,6};
    shellsort(v, 10);
    for (int i=0; i<10; i++) {
        printf("%d ", v[i]);
    }
    printf("\n");
}
Beispiel #10
0
int main()
{
int a[N]= {8,10,3,5,7,4,6,1,9,2};
shellsort(a,sizeof(a)/sizeof(a[0]));
for(int k = 0;k < N;k++)
printf("a[%d] = %d\n",k,a[k]);
return 0;
}
Beispiel #11
0
/*----------------------------------------------------------------------*/
static void showdirs(struct dnode **dn, int ndirs)
{
  //printf("=== ls showdirs\n");
	int i, nfiles;
	struct dnode **subdnp;

#ifdef CONFIG_FEATURE_LS_RECURSIVE
	int dndirs;
	struct dnode **dnd;
#endif

	if (dn == NULL || ndirs < 1)
		return;

	for (i = 0; i < ndirs; i++) {
		if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
			printf("\n%s:\n", dn[i]->fullname);
		}
		subdnp = list_dir(dn[i]->fullname);
		nfiles = countfiles(subdnp);
		if (nfiles > 0) {
			/* list all files at this level */
#ifdef CONFIG_FEATURE_LS_SORTFILES
			shellsort(subdnp, nfiles);
#endif
			showfiles(subdnp, nfiles);
#ifdef CONFIG_FEATURE_LS_RECURSIVE
			if (all_fmt & DISP_RECURSIVE) {
				/* recursive- list the sub-dirs */
				dnd = splitdnarray(subdnp, nfiles, SPLIT_SUBDIR);
				dndirs = countsubdirs(subdnp, nfiles);
				if (dndirs > 0) {
#ifdef CONFIG_FEATURE_LS_SORTFILES
					shellsort(dnd, dndirs);
#endif
					showdirs(dnd, dndirs);
					free(dnd);	/* free the array of dnode pointers to the dirs */
				}
			}
			dfree(subdnp);	/* free the dnodes and the fullname mem */
#endif
		}
	}
}
int main() {
	int v[MAXSIZE] = {2,7,8,5,10,9,3,1,4,6};
	int i;
	
	print(v,MAXSIZE);
	shellsort(v, MAXSIZE);
	print(v,MAXSIZE);

	return 0;
}
Beispiel #13
0
int main(void)
{
  int x[ARRAY_SIZE] = {5, 2, 9, 12, 3, 12, 30, -1, -900, 2149};
  shellsort(x, ARRAY_SIZE);
  for (int i = 0; i < ARRAY_SIZE; ++i)
  {
    printf("%d ", x[i]);
  }
  printf("\n");
}
double* generate_average_from_random_set(double* all_r)
{
		// FIXME
	int n=0, j=0, i=0, k=0, m=0, TOT_ITER=10, subDim=0, totSub=0,*subset=NULL; 
	uint64_t host=0;
	double r=0, sum=0, *all_r_new=NULL; 

	subDim = Settings.n_sub_min; 
	totSub = SubStructure.N_sub;

	fprintf(stdout, "\nGenerating random subset from complete set of Haloes.\n");

	subset = (int*) calloc(subDim, sizeof(int)); 
	all_r = (double*) calloc(subDim, sizeof(double));
	all_r_new = (double*) calloc(subDim, sizeof(double));

		for(j=0; j<TOT_ITER; j++)
		{
			subset = generate_random_subset(totSub, subDim, subset);
			subset = int_shellsort(subset, subDim);
	
			for(i=0; i<totSub; i++)
			{
				host = Haloes[i].host;
				if(i==subset[k] && host != Haloes[i].id) 
				{
					sum = 0;

					for(m=0; m<3; m++)
						sum += pow2(Haloes[host].X[m] - Haloes[i].X[m]); 

					r = sqrt(sum);
					all_r[k] = r/Haloes[host].Rvir;
					k++;
				}
			}

			all_r = shellsort(all_r, subDim);

			for(n=0; n<subDim; n++)
			{
				all_r_new[n] += all_r[n];
			}
		}

		for(i=0; i<subDim; i++) 
			all_r_new[i] /= (double) TOT_ITER;

	return all_r_new;
	
	free(subset);
	free(all_r);
	free(all_r_new);
}
Beispiel #15
0
int main()
{
  int a[] = {4, 5, 3, 1, 2};
  int i;

  shellsort(a, 5);
  for (i = 0; i < 5; i++)
    printf(" %d", a[i]);
  printf("\n");
  return 0;
}
int main() {
    int v[10] = {4, 1, 2, 7, 9, 6, 3, 8, 5, 0};
    int i = 0;

    shellsort(v, sizeof(v) / sizeof(int));

    for(i = 0; i < sizeof(v)/ sizeof(int); i++) {
        printf("%d\t", v[i]);
    }
    printf("\n");
    return 0;
}
int main() {

    int i,
        n, 
        *arr;  

    //call by reference
    arr = read( arr, &n ); 
    shellsort(arr, n);
    write( arr, n);

return(0);
}
Beispiel #18
0
double median(double *array, int size)
{
	int i=0, half_size; 
	double *avg, med; 

	half_size = (int) size / 2;
	avg = (double *) calloc(size, sizeof(double));
	avg = shellsort(array, size);
	
	med = array[half_size];
	
	return med;
}
Beispiel #19
0
int main(){
	int i;
	int elem[10] = {6,3,8,2,5,9,4,5,1,7};
	char s[] = "12345678";
	//int elem[10] = {1,2,3,4,5,6,7,8,9,10};
	//quickSort(elem,0,sizeof(elem)/sizeof(int));
	shellsort(elem,sizeof(elem)/sizeof(int));
	for(i = 0; i < sizeof(elem)/sizeof(int) ; i++)
		printf("%d " , elem[i]);
	printf("\n");
	reverseStr(s,0,strlen(s)-1);
	printf("%s \n",s);
	return 0;
}
Beispiel #20
0
/* shellsort sort the int array use shell sort algorithm.
 * This is a copy of the shellsort program in K&R C 3.5 */
main()
{
	int values[] = {5, 3, 7, 8, 6, 9, 1, 2, 0, 4};
	int i, n = 10;

	shellsort(values, n);

	for (i = 0; i < n; ++i)
	{
		printf("%6d%c", values[i], (i == 4 || i == n - 1) ? '\n' : ' ');
	}

	return 0;
}
Beispiel #21
0
int main()
{
	FILE *fp = fopen("test", "r");
	int arr[100000];
	int i;

	for (i = 0; i < 100000; i++) {
		arr[i] = getc(fp);
	}

	printf("%lu\n", shellsort(arr, 100000));

	return 0;
}
Beispiel #22
0
int main(int argc, const char **argv) {
  srand(time(NULL));
  int upper = atoi(argv[1]) - 1;

  int arr[upper];
  for(int i = 0; i < upper; i++)
    arr[i] = rand();

  shellsort(arr, upper);

  for(int i = 0; i < upper; i++)
    printf("%d\n", arr[i]);

  return 0;
}
Beispiel #23
0
int main()
{
int i,n;
scanf("%d",&n);
int *arr=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
  scanf("%d",&arr[i]);

}
 shellsort(arr,n);
  printRepeating(arr,n);
  return 0;
  
}
int main()
{
    int data[10] = { 9, 12, 54, 90, 0, 100, 65, 32, 54, 81};
    int i;

    for(i = 0; i < 10; ++i) {
        printf("%d\n", data[i]);
    }

    shellsort(data, 10);

    for(i = 0; i < 10; ++i) {
        printf("%d\n", data[i]);
    }

    return 0;
}
void sort_eccentricity()
{
	// FIXME
	int totSub=0, nBins=0, i=0; 
	int *cum_n_ecc=NULL, *n_ecc=NULL;
	double e=0, eMax=0, eMin=0; 
	double *ecc=NULL, *ecc_bin=NULL; 
	
	totSub = SubStructure.N_sub; 
	nBins = Settings.n_bins; 

	fprintf(stdout, "\nSorting eccentricity");
	Settings.tick=0;
	
	ecc = (double*) calloc(totSub, sizeof(double));
	ecc_bin = (double*) calloc(nBins, sizeof(double));
	n_ecc = (int*) calloc(nBins-1, sizeof(int));
	cum_n_ecc = (int*) calloc(nBins-1, sizeof(int));

		for(i=0; i<totSub; i++) 
		{
			ecc[i] = e;
		}	

				ecc = shellsort(ecc, totSub);

			eMin = ecc[0]; eMax = ecc[totSub-1];
			ecc_bin = log_stepper(eMin, eMax, nBins);
			lin_bin(ecc, ecc_bin, nBins, totSub, n_ecc);

	for(i=0; i<nBins-1; i++)
		fprintf(stdout, "m_bin:%e  n_bin:%d\n", ecc_bin[i], n_ecc[i]); 

	for(i=0; i<nBins-1; i++)
	{
		HaloProperties[HALO_INDEX].ecc[i]=ecc_bin[i];
		HaloProperties[HALO_INDEX].n_ecc[i]=n_ecc[i];
	}

	free(ecc);
	free(ecc_bin);
	free(n_ecc);
	free(cum_n_ecc);

	fprintf(stdout, "\n");
}
Beispiel #26
0
int main( int argc, char *argv[] ) {

  int *A, i = 0, count = 0, temp ;

  FILE *fin, *fun ; 

  fun = fopen( argv[ 1 ] , "r" ) ;
  fin = fopen( argv[ 1 ] , "r" ) ; 
 
  while( ( fscanf( fin , "%d", &temp ) ) != EOF ) {
 
   count++ ;
   
  }  

  fclose( fin ) ;

  A = ( int * ) malloc( sizeof( int ) * count ) ;

  while( ( fscanf( fun, "%d", &A[ i ] ) ) != EOF ) i++ ;
  
  shellsort( A, count ) ;

  printf( "\nThe first 5 numbers are." ) ;

  for( i = 0 ; i < 5 ; i++ ) {

    printf( " %d", A[ i ] ) ;

  }

  printf( "\nThe last 5 numbers are." ) ;

  for( i = ( count - 5 ) ; i <= count  ; i++ ) {

    printf( " %d", A[ i ]  ) ;

  }
    
  fclose( fun ) ;

  return  0 ;

}
Beispiel #27
0
int main(int argc, char **argv)
{
  int i;
  int a[7] = {49, 38, 65, 97, 76, 13, 27};
  
  //shellsort(a, 7);
  //maopao(a, 6);
  //quicksort(a, 0, 6);
  for(i=0;i<7;i++)
    printf(" %d", a[i]);
  
  printf("\n");
  
  shellsort(a, 7);
  
  printf("\n");
  
  return 0;
}
int main(void) {
   int distanz_folge;
   float zeit;
   clock_t start, ende;

   for(distanz_folge =2;
     distanz_folge <= MAX_TEST; distanz_folge++) {
      init_test_array();

      start = clock();
      shellsort(test_array, MAX-1, distanz_folge);
      ende = clock();

      /* Ergebnis der Laufzeitmessung in Sekunden */
      zeit = (float)(ende-start) / (float)CLOCKS_PER_SEC;
      printf("Die Laufzeitmessung der Distanzfolge "
         " %d ergab %2.2f  Sekunden\n" ,distanz_folge,zeit);
   }
   return EXIT_SUCCESS;
}
int main()
{
    count=0;
    
    int i;
    int v[] ={13,14,94,33,82,25,59,94,65,23,45,27,73,25,39,10,76};
    int s[] ={13,14,94,33,82,25,59,94,65,23,45,27,73,25,39,10,76};
    
    i= sizeof(v)/sizeof(v[0]);
    shellsort(v,i);
    
    
    printf("%d\n",count);
    
    count=0;
    insertionSort(s,i);
    printf("%d\n",count);
    return 0;

}
Beispiel #30
0
void graph_add_edge(graph_t *g, index_t u, index_t v)
{
    assert(u >= 0 && 
           v >= 0 && 
           u < g->num_vertices &&
           v < g->num_vertices);
    assert(g->has_target == 0);

    if(g->num_edges == g->edge_capacity) {
        g->edges = enlarge(4*g->edge_capacity, 2*g->edge_capacity, g->edges);
        g->edge_capacity *= 2;
    }

    assert(g->num_edges < g->edge_capacity);

    index_t *e = g->edges + 2*g->num_edges;
    g->num_edges++;
    e[0] = u;
    e[1] = v;
    shellsort(2, e);
}