Advertisement
juanjo12x

ggs

Sep 29th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.34 KB | None | 0 0
  1. #ifndef NUMGBASES_H
  2. #define NUMGBASES_H
  3.  
  4. int* tablaI(const int*, int,char);
  5. int* tablaC(const char**,int,char);
  6. int* tablaD(const double*const, int,char);
  7. int divide(int*,int *,int,int);
  8. int divide_v2(double*,int *,int,int);
  9. int divide_v3(const char **,int *,int,int);
  10. void quicksort(int*,int *,int,int);
  11. void quicksort_v2(double*,int*,int,int);
  12. void quicksort_v3(const char**,int*,int,int);
  13. #endif  /* NUMGBASES_H */
  14.  
  15.  
  16. int divide_v3(const char** arreglo,int *indices, int start,int end){
  17.     //gg
  18.     int left,right,pivot,temp;
  19.     pivot=indices[start];
  20.     left=start;right=end;
  21.     while(left<right){
  22.         while(strcmp(arreglo[indices[right]],arreglo[pivot])>0){
  23.             right--;
  24.         }
  25.         while(left<right && strcmp(arreglo[indices[left]],arreglo[pivot])<=0){
  26.             left++;
  27.         }
  28.         if(left<right){
  29.             temp=indices[left];
  30.             indices[left]=indices[right];
  31.             indices[right]=temp;
  32.            
  33.         }
  34.     }
  35.     temp=indices[right];
  36.     indices[right]=indices[start];
  37.     indices[start]=temp;
  38.    
  39.     return right;
  40. }
  41. void quicksort_v3(const char**arreglo,int *indices,int start,int end){
  42.     int pivot;
  43.     if(start<end){
  44.         pivot=divide_v3(arreglo,indices,start,end);
  45.         quicksort_v3(arreglo,indices,start,pivot-1);
  46.         quicksort_v3(arreglo,indices,pivot+1,end);
  47.     }
  48. }
  49. int* tablaC(const char**arreglo,int n,char indicador){
  50.     int *indices,*indices2;
  51.     indices2=new int[100];
  52.     indices=new int[100];
  53.     for(int i=0;i<n+1;i++){
  54.         indices[i]=i;
  55.     }
  56.     if(indicador=='A' || indicador=='a'){
  57.         quicksort_v3(arreglo,indices,0,n);
  58.         return indices;
  59.     }else{
  60.         quicksort_v3(arreglo,indices,0,n);
  61.         //esta ordenado ascendentemnte
  62.         for(int i=0;i<n+1;i++){
  63.             indices2[i]=indices[n-i];
  64.         }
  65.         //for(int i=0;i<n+1;i++) printf("%d\n",indices2[i]);
  66.         delete [] indices;
  67.         return indices2;
  68.     }
  69.    
  70.     //aplico el metodo de ordenacion quicksort
  71.     /*if(indicador=='A' || indicador=='a'){
  72.         quicksort_v2(arr_aux2,indices,0,n);
  73.         delete [] arr_aux2;
  74.         return indices;
  75.     }else{
  76.         quicksort_v2(arr_aux2,indices,0,n);
  77.         //esta ordenado ascendentemnte
  78.         for(int i=0;i<n+1;i++){
  79.             indices2[i]=indices[n-i];
  80.         }
  81.         //for(int i=0;i<n+1;i++) printf("%d\n",indices2[i]);
  82.         delete [] arr_aux2;delete [] indices;
  83.         return indices2;
  84.     }*/
  85. }
  86.  
  87.  
  88. /*------------------------------------*/
  89. int main(int argc, char** argv) {
  90.     //int* arreglo;
  91.     double* arreglo;
  92.     int n;    
  93.     scanf("%d",&n);
  94.     /*arreglo=new int[100];
  95.     for(int i=0;i<n;i++){
  96.         scanf("%d",&arreglo[i]);
  97.     }
  98.     int *index=tablaI(arreglo,n-1,'D');
  99.     for(int i=0;i<n;i++){
  100.         printf("%d ",index[i]);
  101.     }*/
  102.     //prueba tabla de doubles
  103.     /*arreglo=new double[100];
  104.     for(int i=0;i<n;i++){
  105.         scanf("%lf",&arreglo[i]);
  106.     }
  107.     int *index=tablaD(arreglo,n-1,'D');
  108.     for(int i=0;i<n;i++){
  109.         printf("%d ",index[i]);
  110.     }*/
  111.     const char** nombres;
  112.     nombres=new const char* [100];
  113.     getchar();
  114.     for(int i=0;i<n;i++){
  115.         scanf("%s",&nombres[i]);
  116.     }
  117.     for(int i=0;i<n;i++){
  118.        printf("%s\n",&nombres[i]);
  119.     }
  120.     int* index=tablaC(nombres,n-1,'A');
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement