Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int a[10] = {75,33,35,16,91,24,25,43,27,83};
- int pasadas,i,j,almacena,intercambios = 0,comparaciones = 0,arreglo = 10;
- printf( "Arreglo horizontal antes de ordenar" );
- printf( "\n" );
- printf( "Valor \t" );
- for ( i = 0; i < arreglo; i++ )
- {
- printf( "%d \t", a[ i ] );
- }
- printf( "\n" );
- printf( "Posicion\t" );
- for ( i = 1; i < arreglo+1; i++ )
- {
- printf( "%d \t", i );
- }
- for (pasadas = 1; pasadas < arreglo; pasadas++)
- {
- almacena = a[ pasadas ];
- j = pasadas - 1;
- while (j >= 0 && a[j] > almacena)
- {
- a[j + 1] = a[j];
- j--;
- comparaciones++;
- }
- a[j + 1] = almacena;
- intercambios++;
- }
- printf( "\n\n" );
- printf( "Una vez ordenado" );
- printf( "\n" );
- printf( "Valor \t" );
- for ( i = 0; i < arreglo; i++ )
- {
- printf( "%d \t", a[ i ] );
- }
- printf( "\n" );
- printf( "Posicion\t" );
- for ( i = 1; i < arreglo+1; i++ )
- {
- printf( "%d \t", i );
- }
- printf( "\n\n" );
- printf( "Numero de comparaciones efectuadas = %d", comparaciones );
- printf( "\n\n" );
- printf( "Numero de intercambios = %d", intercambios );
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement