Fix Bug in Tim Sort (#3050)

Co-authored-by: Sahil Prafulkumar Parekh <sh883193@dal.ca>
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
This commit is contained in:
Sahil Parekh 2022-05-20 14:19:18 -03:00 committed by GitHub
parent f9b788f7f4
commit 550adb2287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,10 +71,10 @@ class TimSort {
* sorting.
*/
public void insertion_sort(int[] array, int start_idx, int end_idx) {
for (int i = 0; i < array.length; i++) {
for (int i = start_idx; i <= end_idx; i++) {
int current_element = array[i];
int j = i - 1;
while (j >= 0 && array[j] > current_element) {
while (j >= start_idx && array[j] > current_element) {
array[j + 1] = array[j];
j--;
}