From 9e9d30accfe2f2a540bca0840c59f209f5e5ec53 Mon Sep 17 00:00:00 2001 From: jugal Date: Sat, 8 Mar 2025 22:26:57 +0530 Subject: [PATCH] Mod 5 all sorts --- .../com/hithomelabs/princeton1/module5/Shell.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/module5/src/main/java/com/hithomelabs/princeton1/module5/Shell.java b/module5/src/main/java/com/hithomelabs/princeton1/module5/Shell.java index 7abc6fd..a7f23e0 100644 --- a/module5/src/main/java/com/hithomelabs/princeton1/module5/Shell.java +++ b/module5/src/main/java/com/hithomelabs/princeton1/module5/Shell.java @@ -25,9 +25,16 @@ public class Shell extends AbstractCustomSorts { @Override public void sort(E[] arr) { Insertion sortingAlgorithm = new Insertion<>(); - sortingAlgorithm.sort(arr, 7); - sortingAlgorithm.sort(arr, 3); - sortingAlgorithm.sort(arr); + + int h=1, N=arr.length; + while(h < N/3) + h = 3*h + 1; + + while( h >= 1){ + sortingAlgorithm.sort(arr, h); + h=h/3; + } + } private int hsort(E[] arr, int h, MetaData metadata) {