You are viewing a single comment's thread. Return to all comments →
My solution in C:
void print_arr(int arr_count, int* arr){ for (int i = 0; i<arr_count; i++){ printf("%d ", arr[i]); } printf("\n"); } void swap(int* i, int* j){ *i ^= *j; *j ^= *i; *i ^= *j; } void insertionSort2(int n, int arr_count, int* arr) { if (arr_count == 1) printf("%d", arr[0]); else{ for (int i = 1; i<arr_count; i++){ for (int j = i; j > 0; j--){ if (arr[j] < arr[j-1]){ swap(&arr[j], &arr[j-1]); } else{ break; } } print_arr(arr_count, arr); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort - Part 2
You are viewing a single comment's thread. Return to all comments →
My solution in C: