You are viewing a single comment's thread. Return to all comments →
Time Complexity: O(n^2)
Space Complexity: O(1)
void printf_arr(int n, int* arr){ for (int i = 0; i<n; i++){ printf("%d ", arr[i]); } printf("\n"); } void swap(int* a, int* b){ *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } void insertionSort2(int n, int arr_count, int* arr) { if (n == 1) printf("%d", arr[0]); for (int i = 1; i<n ; i++){ int temp_idx = i; while (temp_idx > 0 && arr[temp_idx] < arr[temp_idx-1]){ swap(&arr[temp_idx], &arr[temp_idx-1]); temp_idx --; } printf_arr(n, 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 →
Time Complexity: O(n^2)
Space Complexity: O(1)