16
Abr
11

Clase de algoritmos: Metodos de Ordenamiento

Bubble Sort

void ordenamientoBurbuja(int v[], int util_v) {
         int temp, i, j;

         for (i = 0; i < util_v -1 ; i++) {
                 for (j = i + 1; j < util_v ; j++) {
                         if (v[i] > v[j]) {
                                temp = v[i];
                                v[i] = v[j];
                                v[j] = temp;
                 }
                 }
         }
}

Insert Sort

void insertionSort(int numbers[], int array_size)
{
   int i, a, index;

   for (i=1; i < array_size; i++)
   {
      index = numbers[i];

      for (a=i-1;a >= 0 && numbers[a] > index;a--)
      {
         numbers[a + 1] = numbers[a];
         numbers[a+1] = index;
      }
   }
}

Shell Sort

void shell_sort(int A[], int size)
{
  int i, j, incrmnt, temp;

  incrmnt = size/2;
  while (incrmnt > 0)
  {
    for (i=incrmnt; i < size; i++)
    {
      j = i;
      temp = A[i];
      while ((j >= incrmnt) && (A[j-incrmnt] > temp))
      {
        A[j] = A[j - incrmnt];
        j = j - incrmnt;
      }
      A[j] = temp;
    }
    incrmnt /= 2;
  }
}

Select Sort

void ordsel(int * x, int n)
{
   int minimo=0,i,j;
   int swap;
   for(i=0 ; i<n-1 ; i++)
   {
      minimo=i;
      for(j=i+1 ; j<n ; j++)
         if (x[minimo] > x[j])
            minimo=j;
      swap=x[minimo];
      x[minimo]=x[i];
      x[i]=swap;
   }
}

1 Respuesta to “Clase de algoritmos: Metodos de Ordenamiento”


  1. junio 10, 2013 a las 2:59 pm

    (Thank you rounds are always welcome, of course. You must definitely be planning to make it special and memorable by keeping a good theme, ordering the best food and choosing the best games.
    The food is decent and the drink specials on Tuesdays include $2.


Deja un comentario


abril 2011
L M X J V S D
 123
45678910
11121314151617
18192021222324
252627282930  

Blog Stats

  • 205.134 hits