Presentation is loading. Please wait.

Presentation is loading. Please wait.

Insertion sort void insertion_sort (int a[ ],int N) { int i, j, v; a[0] = INT_MIN; for (i=2; i<=N; i++) { v=a[i]; j=i; while ( a[j-1]>v) { a[j]=a[j-1];

Similar presentations


Presentation on theme: "Insertion sort void insertion_sort (int a[ ],int N) { int i, j, v; a[0] = INT_MIN; for (i=2; i<=N; i++) { v=a[i]; j=i; while ( a[j-1]>v) { a[j]=a[j-1];"— Presentation transcript:

1 Insertion sort void insertion_sort (int a[ ],int N) { int i, j, v; a[0] = INT_MIN; for (i=2; i<=N; i++) { v=a[i]; j=i; while ( a[j-1]>v) { a[j]=a[j-1]; j--; } a[j]=v; }

2 void ordina(int a[], const int n) { int i, j, v, t; for (i=n;i>1;i--) if (a[i-1]>a[i]){ t = a[i-1]; a[i-1]= a[i]; a[i]=t; } // minimo nella prima posizione for (i=2; i<=n; i++){ v=a[i]; j=i; while ( a[j-1]>v) { a[j]=a[j-1]; j--; } a[j]=v; } Algoritmo Insertion sort senza sentinella

3 13 Int Min 3254 i v j Insertion sort NO SI Presentazione realizzata dall’ing. G. Marti v=a[i]; j=i a[j-1]>v a[j]=a[j-1]; j-- a[j]=v i++ 1 il ciclo continua …


Download ppt "Insertion sort void insertion_sort (int a[ ],int N) { int i, j, v; a[0] = INT_MIN; for (i=2; i<=N; i++) { v=a[i]; j=i; while ( a[j-1]>v) { a[j]=a[j-1];"

Similar presentations


Ads by Google