Hola.
Revisa este modo:
Código PHP:
#include <stdio.h>
#include <stdlib.h>
void insertSort(int *, int);
int main()
{
int a[] = { 50,2,2,100,5,3,1,7,9 };
int b[] = { 4,2,6,10,8 };
int i;
int asz = sizeof( a ) / sizeof( a[0] );
int bsz = sizeof( b ) / sizeof( b[0] );
// pasar: a y b -> c
int *c = ( int* ) malloc( sizeof(int) * ( asz + bsz ) );
for ( i = 0; i < asz; i++ ) c[i] = a[i];
for ( i = 0; i < bsz; i++ ) c[asz+i] = b[i];
// mostrar original
for ( i = 0; i < asz + bsz; i++ ) printf( "%d ",c[i] ); printf( "\n\n" );
// ordenar
insertSort(c, (asz+bsz) );
// mostrar ordenado
for ( i = 0; i < asz + bsz; i++ ) printf( "%d ",c[i] );
free( c );
getchar();
return 0;
}
// ordenamiento por inserción
void insertSort( int *array, int size )
{
int i,j, tmp;
for( i = 1; i < size; ++i ) {
tmp = array[i];
j = i;
while ( j > 0 && tmp < array[j - 1] ) {
array[j] = array[j - 1];
j--;
}
array[j] = tmp;
}
}
Salida:
Saludos
