Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "time.h"
  4. #define TRUE 1
  5. #define FALSE 0
  6.  
  7. int A[2000],AOUNO[2000],B[3000],C[4000],D[5000],E[6000],F[7000];
  8. FILE *doc;
  9.  
  10. void num_random(int vec[], int tam)
  11. {
  12.  
  13. srand(time(NULL));
  14.  
  15. for (int i = 0; i < tam; ++i)
  16. {
  17. vec[i]=(rand()%10000)+1;
  18. }
  19.  
  20. }
  21.  
  22. void reducirder(int ini, int fin,int vec[]){
  23.  
  24. int izq, der, pos, aux, band;
  25. izq=ini;
  26. der=fin;
  27. pos=fin;
  28. band=TRUE;
  29.  
  30. while(band==TRUE){
  31. band=FALSE;
  32. while(vec[pos]>=vec[izq] && pos!= izq)
  33. izq=izq+1;
  34. if(pos!=izq){
  35. aux=vec[pos];
  36. vec[pos]=vec[izq];
  37. vec[izq]=aux;
  38. pos=izq;
  39.  
  40. while(vec[pos]<= vec[der] && pos != der)
  41. der=der-1;
  42. if(pos != der){
  43. band=TRUE;
  44. aux=vec[pos];
  45. vec[pos]=vec[der];
  46. vec[der]=aux;
  47. pos=der;
  48. }
  49. }
  50. }
  51. if((pos-1) >ini)
  52. reducirder(ini,pos-1,vec);
  53. if(fin > (pos +1))
  54. reducirder(pos+1,fin,vec);
  55. }
  56.  
  57. void reducirizq(int ini, int fin,int vec[]){
  58.  
  59. int izq, der, pos, aux, band;
  60. izq=ini;
  61. der=fin;
  62. pos=ini;
  63. band=TRUE;
  64.  
  65. while(band==TRUE){
  66. band=FALSE;
  67. while(vec[pos]<= vec[der] && pos != der)
  68. der=der-1;
  69. if(pos != der){
  70. aux=vec[pos];
  71. vec[pos]=vec[der];
  72. vec[der]=aux;
  73. pos=der;
  74. while(vec[pos]>=vec[izq] && pos!= izq)
  75. izq=izq+1;
  76. if(pos!=izq){
  77. band=TRUE;
  78. aux=vec[pos];
  79. vec[pos]=vec[izq];
  80. vec[izq]=aux;
  81. pos=izq;
  82. }
  83. }
  84. }
  85. if((pos-1) >ini)
  86. reducirizq(ini,pos-1,vec);
  87. if(fin > (pos +1))
  88. reducirizq(pos+1,fin,vec);
  89. }
  90.  
  91. void quicksortizq(int vec[],int N){
  92. reducirizq(0,N-1,vec);
  93. }
  94.  
  95. void quicksortder(int vec[],int N){
  96. reducirder(0,N-1,vec);
  97. }
  98.  
  99. int main()
  100. {
  101.  
  102. doc = fopen("tiempos.txt","w");
  103.  
  104. //Variables aux
  105. int tamano;
  106. clock_t inicio, fin;
  107. //procesando vector de 2000 izq
  108. tamano=sizeof(A)/sizeof(int);
  109. num_random(A,tamano);
  110. for(int i=0;i<tamano;i++) A[i]=AOUNO[i];
  111.  
  112. inicio=clock();
  113. quicksortizq(AOUNO,tamano);
  114. fin=clock();
  115. printf("%f\n", (float)(fin-inicio)/(float)CLOCKS_PER_SEC);
  116. fprintf(doc,"A[1]=%f \n",(float)(fin-inicio)/(float)CLOCKS_PER_SEC);
  117. //
  118. //procesando vector de 2000 der
  119. //Copiando vector
  120. for(int i=0;i<tamano;i++) A[i]=AOUNO[i];
  121. inicio=clock();
  122. quicksortder(AOUNO,tamano);
  123. fin=clock();
  124. printf("%f\n", (float)(fin-inicio)/(float)CLOCKS_PER_SEC);
  125. fprintf(doc,"A[N]=%f \n",(float)(fin-inicio)/(float)CLOCKS_PER_SEC);
  126. //
  127.  
  128. fclose(doc);
  129. system("pause");
  130. return 0;
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement