• Viernes 29 de Marzo de 2024, 14:19

Autor Tema:  ordenamiento por cubetas  (Leído 7411 veces)

eruelas

  • Miembro activo
  • **
  • Mensajes: 69
  • Nacionalidad: mx
    • Ver Perfil
ordenamiento por cubetas
« en: Martes 3 de Marzo de 2009, 04:11 »
0
Hola a todos kisiera saber si alguien me puede dar un ejemplo del metedo de ordenacion por cubetas y si es posible codigo y/o descripcion dl  procedimiento de vdd se los agradeceria mucho gracias de antemano

manuel_vzla

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Re:ordenamiento por cubetas
« Respuesta #1 en: Lunes 22 de Octubre de 2012, 16:56 »
0
Código: C
  1. #include<stdio.h>
  2. void modifica_cubeta(int [],int ,int);
  3. main()
  4. {
  5.       int i;
  6.       int j;
  7. int N;
  8.    int z=0;
  9.  
  10.  printf("cantidad de elementos\n");  
  11.       scanf("%d",&N);
  12.    
  13.     int tem[N];
  14.     int tem1[N];
  15.     int Arreglo[N][10];
  16.     int copia[10][10];        
  17.     int temp[N];
  18.    
  19.    int aux[N];
  20.     int c[N];
  21.      
  22.    
  23.     printf("introduzca los elementos\n");
  24.             for(i=0;i<N;i++)
  25.  
  26.                  scanf("%d",& aux[i]);
  27.  
  28.            
  29.       for(i=0;i<N;i++)
  30.          c[i]=aux[i];
  31.    
  32.  
  33.  
  34.             for(j=0;j<10;j++)
  35.                       for(i=0;i<N;i++)        
  36.                              Arreglo[i][j]=0;
  37.  for(j=0;j<10;j++)
  38.            for(i=0;i<10;i++)        
  39.             copia[i][j]=0;  
  40.  
  41.   modifica_cubeta(aux,N,1);
  42.  
  43.   for(j=0;j<10;j++)
  44.             for(i=0;i<N;i++)  {
  45.                                    
  46.      temp[i]=aux[i];
  47.      //printf("%d  ",temp[i]);
  48.    
  49.      Arreglo[i][aux[i]]=c[i];
  50.      tem[i]=Arreglo[i][j];
  51.  
  52.      if(Arreglo[i][j]>0){
  53.        modifica_cubeta(tem,N,2);
  54.      printf("%d  ",tem[i]);
  55.       c[i]=Arreglo[i][j];
  56.      copia[aux[i]][tem[i]]=c[i];
  57.    
  58.          }
  59.      
  60.      
  61. }
  62.        
  63. for(j=0;j<10;j++)
  64.             for(i=0;i<10;i++)  {      
  65.        
  66.         if(i%10==0)
  67.         printf("\n");
  68.       printf("%3d  ",copia[i][j]);
  69.         }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  //system("pause");
  77.  }
  78.  
  79. void modifica_cubeta(int b[],int n ,int pasada)
  80. {
  81.       int casilla;
  82.    int i,j;
  83.  
  84.     int n_tem;
  85.         int n_temp[10*n][10*n];
  86.         int n_temp1[10*n][10*n];
  87.  
  88.  
  89.  for(j=0;j<=10*n;j++)    
  90.        
  91.          for(i=0;i<n;i++)
  92.          
  93.                      
  94.           {                    
  95.                
  96.                 n_tem=b[i];
  97.                
  98.            
  99.                         n_temp[i][j]=n_tem/10;
  100.                 n_temp1[i][j]=n_tem%10;
  101.          
  102.            
  103.          
  104.                         if(j>=1)
  105.                         {
  106.                    
  107.                         n_temp[i][j]=n_temp[i][j-1]/10;
  108.                    
  109.              }
  110.             if(j>=2){
  111.              
  112.                        
  113.                n_temp1[i][j-2]= n_temp1[i][j];
  114.                    n_temp1[i][j]=n_temp[i][j-2]%10;
  115.                      
  116.            }
  117.            
  118.            
  119.          if(j>0){        
  120.    
  121.  
  122.            
  123.     if(j==pasada){            
  124.                b[i]=n_temp1[i][j];     
  125.  
  126.                  }          
  127.              
  128.      
  129.                  
  130.                 }
  131.    
  132.  
  133.    
  134.  
  135.  
  136.  
  137.  
  138.  
  139.        }
  140. }
  141.