From 9bd54eef832e38448954558ae299e9cc8c787068 Mon Sep 17 00:00:00 2001 From: Samuel Tan Date: Fri, 23 Feb 2018 13:18:01 +0800 Subject: [PATCH] Fix the bug on insertion sort code --- sort.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sort.html b/sort.html index c3592b3..39eea51 100644 --- a/sort.html +++ b/sort.html @@ -179,12 +179,11 @@

Insertion sort

el = arr[i]; j = i; - while(j>0 && arr[j-1]>toInsert){ + while(j>0 && arr[j-1]>arr[j]){ arr[j] = arr[j-1]; j--; - } - - arr[j] = el; + arr[j] = el; + } } return arr;