예제 #1
0
파일: 201102435_04.c 프로젝트: MS-Park/CNU
void Quick_Sort(int *S,int p,int r){
	int q;
	if(p<r){
		q = Partition(S,p,r);
		Quick_Sort(S,p,q-1);
		Quick_Sort(S,q+1,r);
	}
}
예제 #2
0
파일: 43.c 프로젝트: JackDrogon/Study
void Quick_Sort(int low,int high)
{ /* 对R[low..high]快速排序 */
     int pivotpos; /* 划分后的基准记录的位置 */
     if(low<high){/* 仅当区间长度大于1时才须排序 */
	pivotpos=Partition(low,high); /* 对R[low..high]做划分 */
        Quick_Sort(low,pivotpos-1); /* 对左区间递归排序 */
        Quick_Sort(pivotpos+1,high); /* 对右区间递归排序 */
      }
} /* end of Quick_Sort */
예제 #3
0
void Quick_Sort(datatype *arr, int s, int t)
{
    if (s < t)
    {
	int m = Partion(arr, s, t);
	Quick_Sort(arr, s, m - 1);
	Quick_Sort(arr, m + 1, t);
    }
    
}
예제 #4
0
void Quick_Sort(int r[], int hs, int ht){
	/*对r[hs]到r[ht]进行快速排序*/
	int i;
	if(hs < ht){
		/*只有1个记录或者无记录时无须排序*/
		i = Partition(r, hs, ht);            /***r[hs] 到 r[ht] 一次划分***/
		Quick_Sort(r, hs, i - 1);           /*递归处理左区间*/
		Quick_Sort(r, i + 1, ht);           /*递归处理右区间*/
	}
}
예제 #5
0
int* Quick_Sort(int* input_array, int start, int end)
{
	int pivot;
	if(end>start)
	{
		pivot = split_array(input_array, start, end);
		Quick_Sort(input_array,start,pivot-1);
		Quick_Sort(input_array,pivot+1,end);

	}
	return input_array;
}
예제 #6
0
파일: quick.c 프로젝트: sysilion/Sorting
void quick() {
	extern int *input;
	int *copy_input[LOOP_COUNT];
	int i, j;

	// Time check variable
	double time;
	BOOL err;

	for (i = 0; i < LOOP_COUNT; i++){
		copy_input[i] = (int *) malloc(sizeof(int) * DATA_SIZE);
		for (j = 0; j < DATA_SIZE; j++) { // copy data
			copy_input[i][j] = input[j];
		}
	}

	CHECK_TIME_START;
	for (i = 0; i < LOOP_COUNT; i++) {
		Quick_Sort(copy_input[i], DATA_SIZE);

		//		if(x%(LOOP_COUNT/10) == 0) printf("*");
		//		printf("Selecting Result --> input[%d] : %d\n", result, input[result]);
	}
	CHECK_TIME_END(time, err);

	//	// data output check
	//	for (i = 0; i < DATA_SIZE; i++) {
	//		if(i%(DATA_SIZE/10) == 0) printf("%d : %d, ", i, copy_input[i]);
	//	}

	//	printf(" Calc Time = %.0fus\n", time/LOOP_COUNT);
	printf("%.0f\n", time / LOOP_COUNT);
}
예제 #7
0
파일: 43.c 프로젝트: JackDrogon/Study
void main()
{
	int i,n;
	clrscr();
	puts("Please input total element number of the sequence:");
	scanf("%d",&n);
	if(n<=0||n>MAX)
	{
		printf("n must more than 0 and less than %d.\n",MAX);
		exit(0);
	}
	puts("Please input the elements one by one:");
	for(i=1;i<=n;i++)
		scanf("%d",&R[i]);
	puts("The sequence you input is:");
	for(i=1;i<=n;i++)
		printf("%4d",R[i]);
	Quick_Sort(1,n);
	puts("\nThe sequence after quick_sort is:");
	for(i=1;i<=n;i++)
		printf("%4d",R[i]);
	puts("\n Press any key to quit...");
	getch();
	
}
예제 #8
0
/*	匹配输出
	参数:搜索键、对应桶的位置
	功能:在桶内检索所有搜索键,找到匹配的后将其存入缓冲数组中(用于排序,这部分不限制页面所以开了大数组)
		  检索结束后,对缓冲数组的元组进行快速排序,并写入文件中	*/
void Match_And_Output(int Search_Key,int Position){
	Tuple Temp;
	int i,j,count=0,Part_Key_Set[100];
	Tuple Tuple_Set[100];
	FILE* File_Pointer=fopen(OUT,"rt+");
	for(i=0;i<*(Bucket_Set[Position].Tail-2);i++){
		Temp.Lenth=*(Bucket_Set[Position].Tail-3-i*2);
		for(j=0;j<Temp.Lenth;j++)
			Temp.Info[j]=Bucket_Set[Position].Head[*(Bucket_Set[Position].Tail-4-i*2)+j];
		if(Get_Search_Key(Temp)==Search_Key){
			Part_Key_Set[count]=Get_Part_Key(Temp);
			Tuple_Set[count]=Temp;
			count++;
		}
	}	
	Quick_Sort(Part_Key_Set,Tuple_Set,count+1);
	for(i=0;i<count+1;i++){
		fseek(File_Pointer,0,SEEK_END);
		fwrite(Tuple_Set[i].Info,Tuple_Set[i].Lenth,1,File_Pointer);
		IO++;
		fprintf(File_Pointer,"\r\n");
	}
	fprintf(File_Pointer,"-1\r\n");
	fclose(File_Pointer);
}
예제 #9
0
int main()
{
    datatype arr[10] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    Print(arr, 10);
    Quick_Sort(arr, 0, 9);
    Print(arr, 10);
    return 0;
}
예제 #10
0
NODE* string_to_tree_converter(char *input_array)
{
	int *integer_array = string_to_array(input_array);
	integer_array = Quick_Sort(integer_array,0,array_length(integer_array)-1);
	NODE* output =  array_to_tree_convertor(integer_array,0,array_length(integer_array));
	free(integer_array);
	return output;
}
예제 #11
0
void main() {
	int a[9]={0, 49, 38, 65, 97, 76, 13, 27, 49};
	printf("排序前:");
	DispList(a,8);
	Quick_Sort(a, 1, 8);
	printf("排序后:");
	DispList(a,8);
}
예제 #12
0
파일: quick.c 프로젝트: sysilion/Sorting
void Quick_Sort (int array[], int size) {
    int i, j, p, t;
    if (size < 2)
        return;
    p = array[size / 2];
    for (i = 0, j = size - 1;; i++, j--) {
        while (array[i] < p)
            i++;
        while (p < array[j])
            j--;
        if (i >= j)
            break;
        t = array[i];
        array[i] = array[j];
        array[j] = t;
    }
    Quick_Sort(array, i);
    Quick_Sort(array + i, size - i);
}
예제 #13
0
/*********************************************************************
*	FUNCTION:		Quick_Sort
*	DESCRIPTION:	Sort numbers in array using quick sort
*	INPUT:
*		Parameters:	list[] - array of numbers
*					high - top spot in array
*					low - bottom spot of array
*	OUTPUT:	
*	PROTOTYPE: void Quick_Sort(int list[], int high, int low);
**********************************************************************/
void Quick_Sort/*(Version1)*/(int list[], int high, int low){

	int pivot;
	int listTemp;

	if(high>low){// stop condition check if high is still higer than low
		
		pivot = list[low];

		int left = low+1;
		int right = high;

		while(left <= right){
			if(list[left] <= pivot){
				left++;
			}
			else{// if left index is pointing at a value over pivot
				if(list[right]>pivot){
					right--;
				}
				else{// if both indexes are pointing at numbers that belong on the other side of the partition
					listTemp = list[left];
					list[left] = list[right];
					list[right] = listTemp;
				}
			}// end if list low > list 0
		}// end while low < high
			
		listTemp = list[right];// swaps pivot back into the middle point
		list[right] = list[low];
		list[low] = listTemp;

		Quick_Sort(list, right-1, low);
		Quick_Sort(list, high, right+1);
		
	}// end if high passes low
}
예제 #14
0
int main(void){
	int status = 0;
        GET_LENGTH(a,length);
	status = Quick_Sort(a);

	if(status != 1)
		printf("Fail to sort with some error");
	else{
		int i;
		for(i = 0; i < length; i++)
			printf("%d ",a[i]);
	}
	printf("\n");
	return 0;
}
예제 #15
0
파일: 201102435_04.c 프로젝트: MS-Park/CNU
void main(){
	FILE* fp;
	FILE* fop;

	LARGE_INTEGER start,end,freq;
	int* data = (int*)malloc(sizeof(int));
	int i = 0;
	int cnt = 0;

	fp = fopen("data04.txt","rt");
	fop = fopen("00_201102435_output.txt","wt");

	if(fp == NULL)
	{
		printf("**** Input File open Error **** \n");
		exit(1);
	}

	while(!feof(fp)){
		data= (int*)realloc(data, sizeof(int)*(cnt+1));
		fscanf(fp, "%d,", &data[cnt]);
		cnt++;
	}
	
	QueryPerformanceFrequency(&freq);
	QueryPerformanceCounter(&start);
	//Randomized_partition(data,0,cnt-1);
	Quick_Sort(data,0,cnt-1);
	QueryPerformanceCounter(&end);
	for(; i<cnt; i++){
		printf("%d ", data[i]);
		fprintf(fop,"%d,", data[i]);
	}
	printf("\n");
	printf("time = %.8f", (float)(end.QuadPart - start.QuadPart)/freq.QuadPart);
	printf("\n");
	free(data);
	fclose(fp);
	fclose(fop);
}
예제 #16
0
 void QS() { if(T == list){  } else { Quick_Sort(tab, 0, (tab.Size()-1)); } }