All pastes #1946050 Raw Edit

Something

public text v1 · immutable
#1946050 ·published 2010-09-21 19:19 UTC
rendered paste body
#include <stdio.h>
#include "sorting.h"

long *Load_File(char *Filename, int *Size){

	#define LN 20
	FILE * infile;
	char Numints[LN];
	int i; 
	long *Array;

	infile=fopen(Filename,"r");
	fgets(Numints,LN,infile);
	*Size=atoi(Numints);
	Array=(long*)malloc(*Size*sizeof(long));

	for(i=0;i<*Size;i++){
		fgets(Numints,LN,infile);
		Array[i]=atoi(Numints);
		printf("%d ",Array[i]);
	}

	return(Array);

}


int Save_File(char *Filename, long *Array, int Size){
	int i;
	FILE * outfile;

	outfile=fopen(Filename,"w");

	fprintf(outfile,"%d\n",Size);
	for(i=0;i<Size;i++){
		fprintf(outfile,"%ld\n",Array[i]);
	}
	fclose(outfile);
	return(1000);
}

void Shell_Insertion_Sort(long *Array, int Size, double *NComp, double *Nmove){

	int i=0, j, k, temp, Inst2 = 0, Inst3 = 0, LEN=500, seqcnt;
	int pratt[LEN];

	pratt[0] = 1;
	while(pratt[i]<Size){
		i++;
/*		if(i>LEN){
			LEN=LEN*1.5;
			pratt2=(int*)realloc(pratt,LEN*sizeof(int));
			
		}*/
		if (pratt[Inst2]*2 < pratt[Inst3]*3) {
			pratt[i] = pratt[Inst2]*2;
			Inst2++;
		}	
		else if (pratt[Inst2]*2 > pratt[Inst3]*3) {
			pratt[i] = pratt[Inst3]*3;
			Inst3++;
		}
		else {
			pratt[i] = pratt[Inst2]*2;
			Inst2++;
			Inst3++;
		}
	
	}

	for(seqcnt=i-1;seqcnt>=0;seqcnt--){
		printf("here\n");
		k=pratt[seqcnt];
		for(j=k;j<Size;j++){
			printf("in for\n");
        		temp=Array[j];
			*Nmove++;
        		i=j;
        		while(i>=k && Array[i-k]>temp){
				printf("in while\n");
				*NComp++;
			 	if(Array[i-k]>temp){
                			Array[i]=Array[i-k];
					*Nmove++;
				}
                		i=i-k;
        		}
        		Array[i]=temp;
			*Nmove++;
		}
	}

}

void Improved_Bubble_Sort(long *Array, int Size, double *Ncomp, double *Nmove){

int k=0;

while(k!=0){
k++;

}
}