You are viewing a single comment's thread. Return to all comments →
My solution in C:
void insertionSort(int N, int arr[]) { int i,j; int value; for(i=1;i<N;i++) { value=arr[i]; // insert value j=i-1; while(j >= 0 && value<arr[j]) // decrease the j index { arr[j+1]=arr[j]; j=j-1; } arr[j+1]=value; // in swap index } for(j=0;j<N;j++) { printf("%d",arr[j]); printf(" "); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Correctness and the Loop Invariant
You are viewing a single comment's thread. Return to all comments →
My solution in C: