fix py decrement missing and in C move j-- to correct spot
This commit is contained in:
parent
82d3973ade
commit
dc8d382910
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue