Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------//
- // INSERTION SORT //
- //---------------------------------------------------------------//
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define n 10
- //---------------------------------------------------------------//
- void insertion( int v[n] )
- {
- int i, j, x, cont = 0;
- for( j = 1 ; j < n ; j++ )
- {
- x = v[j];
- for( i = j-1 ; (i >= 0) && (v[i] > x) ; i-- )
- {
- v[i+1] = v[i];
- cont++;
- }
- }
- printf("cont = %d\n\n", cont);
- }
- //---------------------------------------------------------------//
- int main (void)
- {
- int y, m[n];
- for( y = 0 ; y < n ; y++ ) scanf("%d", &m[y]);
- insertion(m[n]);
- for( y = 0 ; y < n ; y++ ) printf("m[%d] = %d", y, m[y]);
- return 0;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement