Ver Mensaje Individual
  #5 (permalink)  
Antiguo 18/11/2010, 10:07
Avatar de nup_
nup_
 
Fecha de Ingreso: noviembre-2010
Mensajes: 265
Antigüedad: 13 años, 5 meses
Puntos: 32
Respuesta: Metodo de ordenacion

Hola:

Prueba con esto a ver:
Código C++:
Ver original
  1. void ordenar( int arr[] , int n )
  2. {
  3.     int i = 0;
  4.     int j = n - 1;
  5.     bool buscando_max = true;
  6.     while ( i < j )
  7.     {
  8.         int pos_max_o_min = -1 ;
  9.         int max_o_min = arr[buscando_max ? 0 : n-1];
  10.         for ( int pos = i ; pos <= j ; ++pos )
  11.         {
  12.             if ( (arr[pos] >= max_o_min && buscando_max)
  13.                     || (arr[pos] <= max_o_min && !buscando_max) )
  14.             {
  15.                 max_o_min = arr[pos];
  16.                 pos_max_o_min = pos;
  17.             }
  18.         }
  19.         if ( pos_max_o_min != -1 )
  20.         {
  21.             int x = buscando_max ? j : i;
  22.             int temp = arr[pos_max_o_min];
  23.             arr[pos_max_o_min] = arr[x];
  24.             arr[x] = temp;
  25.         }
  26.         if ( buscando_max )
  27.             j--;
  28.         else
  29.             i++;
  30.         buscando_max = !buscando_max;
  31.     }
  32. }

slds;

Nup_