看板 NCTU-STAT98G 關於我們 聯絡資訊
#include <stdio.h> #include <stdlib.h> #include <math.h> void qsF(double *,int, int); int main() { int i,j,k; int n; //size of data int index; double temp,temp2; double *data; printf("Input the size of data:"); scanf("%d",&n); data = (double *) malloc (n*sizeof(*data)); for (i=0;i<n;i++) { data[i] = rand()/32767.0; printf("%lf\n",data[i]); } system("pause"); qsF(data,0,n-1); for (i=0;i<n;i++) printf("%lf\n",data[i]); return 0; } void qsF(double *data,int left, int right) { int i,j; double temp,temp2; temp = data[(left+right)/2]; i = left; j = right; do{ while (data[i] < temp && i < right) i++; while (temp < data[j] && j > left) j--; if ( i<=j ) { temp2 = data[i]; data[i] = data[j]; data[j] = temp2; i++; j--; } }while (i<=j); if (j>left) qsF(data,left,j); if (i<right) qsF(data,i,right); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.7.248
markoo :同學,以上是今天上課的檔案 希望可以有所幫助 07/21 12:44
markoo :PS:以上是在VC++6.0下執行的結果 與studio 2008 07/21 13:12
markoo :有些許出入:D 07/21 13:12