From 952accaf4808a3439dbf5104393d03b4795a63d9 Mon Sep 17 00:00:00 2001 From: MattBizzo Date: Mon, 23 Oct 2017 21:01:02 -0200 Subject: [PATCH] Code changes by request --- Sorts/CocktailShakerSort.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sorts/CocktailShakerSort.java b/Sorts/CocktailShakerSort.java index 594ef1bf..4db840d9 100644 --- a/Sorts/CocktailShakerSort.java +++ b/Sorts/CocktailShakerSort.java @@ -1,4 +1,3 @@ -package Sorts; /** * @@ -18,10 +17,12 @@ class CocktailShakerSort { **/ public static > void CS(T array[], int last) { + // Sorting boolean swap; do { swap = false; + //front for (int count = 0; count <= last - 2; count++) { int comp = array[count].compareTo(array[count + 1]); @@ -32,10 +33,12 @@ class CocktailShakerSort { swap = true; } } - if (!swap) { //break if no swap occurred + //break if no swap occurred + if (!swap) { break; } swap = false; + //back for (int count = last - 2; count >= 0; count--) { int comp = array[count].compareTo(array[count + 1]); @@ -47,7 +50,8 @@ class CocktailShakerSort { } } last--; - } while (swap); //end + //end + } while (swap); } // Driver Program