diff --git a/5_practice.c b/5_practice.c index 70d6651..1c4b351 100644 --- a/5_practice.c +++ b/5_practice.c @@ -2,38 +2,87 @@ #include // for memory allocation #include // for time calculation #include // for sine and cosine functions + int main() { // Declare all the variables - int k, n, N; + int k, n, N, i; double *x, *yr, *yi; - time_t t; - - // Input the number N + double *yr1,*yi1; + double an,bn,a0,b0,a,b; + double temp,dr,di; + time_t t,t1; - - // Locate the memory for x, yr, yi; + // Input the number N + printf("Input the number N :"); + scanf("%d",&N); - // Initial setting for x, for example, x[k] = k - - + // Locate the memory for x, yr, yi; + x = (double *) malloc(N*sizeof(double)); + yr = (double *) malloc(N*sizeof(double)); + yi = (double *) malloc(N*sizeof(double)); + yr1 = (double *) malloc(N*sizeof(double)); + yi1 = (double *) malloc(N*sizeof(double)); + // Initial setting for x, for example, x[k] = k + for(k=0;k // for printf function +#include // for memory allocation +#include // for time calculation +#include // for sine and cosine functions +int quick_sort(double *x, int L, int R); +double quick_sort_median(double *x, int L, int R, int M1,int bl); +double quick_sort_median1(double *x, int L, int R, int M1); +int main() { + // Declare all the variables + int k, m, n, N; + double *x, *y, z, p , med, med1, med2,q1,q3; + time_t t,t1,t2; + + // Input the number N + printf("Input N: "); + scanf("%d",&N); + + // Locate the memory for x and y; + x = (double *) malloc(N*sizeof(double)); + y = (double *) malloc(N*sizeof(double)); + // Initial setting for x, for example, x[k] = 1.0*rand()/RAND_MAX + + srand( time(NULL) ); + for(k=0;k x[k]) { + z = x[n]; + x[n] = x[k]; + x[k] = z; + } + } + } + for(k=0;k= R){ + return 0; + } + p = x[R-1]; + n = L; + + for(k=L;k= R){ + return 0; + } + + p = x[R-1]; + n = L; + for(k=L;k M1){ + quick_sort_median(x,L,n,M1,bl); + } + else if(n < M1){ + quick_sort_median(x,n+1,R,M1,bl); + } + else{ + if(bl){ + return x[n]; + } + else{ + quick_sort_median(x,n+1,R,M1+1,bl); + return (x[n]+x[n+1])/2.0; + } + } +} + +double quick_sort_median1(double *x, int L, int R, int M1){ + int k, n,m; + double z, p; + if(L >= R){ + return 0; + } + + p = x[R-1]; + n = L; + for(k=L;k M1){ + quick_sort_median1(x,L,n,M1); + } + else if(n < M1){ + quick_sort_median1(x,n+1,R,M1); + } + else{ + return x[n]; + } + +}