fix py decrement missing and in C move j-- to correct spot

This commit is contained in:
Emanuel Rodriguez 2023-08-07 23:29:47 -07:00
parent 82d3973ade
commit dc8d382910
2 changed files with 5 additions and 2 deletions

View File

@ -9,8 +9,10 @@ void insertion_sort(int arr[], int len) {
while (j >= 0) {
if (temp < arr[j]) {
arr[j + 1] = arr[j];
j--;
} else {
break;
}
j--;
}
arr[j + 1] = temp;
}
@ -25,7 +27,7 @@ void print_array(int arr[], int len) {
}
int main() {
int arr[10] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int arr[10] = {10, 9, 8, 7, 6, 5, 4, 3, 1, 2};
insertion_sort(arr, 10);
print_array(arr, 10);
}

View File

@ -6,6 +6,7 @@ def insertion_sort(array):
while position >= 0:
if array[position] > temp_value:
array[position + 1] = array[position]
position -= 1
else:
break
array[position + 1] = temp_value