From e92ccf71bf73e435713befa42738896d30837443 Mon Sep 17 00:00:00 2001 From: evmap Date: Tue, 23 Aug 2016 08:32:51 +0700 Subject: [PATCH] fix flip optimization in pancake sort function --- algorithm/sorting/pancake/basic/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithm/sorting/pancake/basic/code.js b/algorithm/sorting/pancake/basic/code.js index a51da1e2..61d99aab 100644 --- a/algorithm/sorting/pancake/basic/code.js +++ b/algorithm/sorting/pancake/basic/code.js @@ -21,7 +21,7 @@ for (var i=0;i { return (curr > prev.val) ? { idx: idx, val: curr} : prev; }, {idx: 0, val: currArr[0]}); - if (currMax.idx !== i) { + if (currMax.idx !== 0) { // if currMax.idx === 0 that means max element already at the bottom, no flip required logger._print('flip at ' + (currMax.idx+i) + ' (step 1)'); flip(currMax.idx+i, N); logger._print('flip at ' + (i) + ' (step 2)');