From 080ba45ff734248ddaccffa3e1c493e59487cf06 Mon Sep 17 00:00:00 2001 From: Aastha1035 <103962002+Aastha1035@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:27:54 -0700 Subject: [PATCH] Create shell sort.cpp --- Sorting/shell sort.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Sorting/shell sort.cpp diff --git a/Sorting/shell sort.cpp b/Sorting/shell sort.cpp new file mode 100644 index 0000000..04cdff9 --- /dev/null +++ b/Sorting/shell sort.cpp @@ -0,0 +1,44 @@ +class ShellSort +{ + static void printArray(int arr[]) + { + int n = arr.length; + for (int i=0; i 0; gap /= 2) + { + + for (int i = gap; i < n; i += 1) + { + + int temp = arr[i]; + + + int j; + for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) + arr[j] = arr[j - gap]; + arr[j] = temp; + } + } + return 0; + } + public static void main(String args[]) + { + int arr[] = {12, 34, 54, 2, 3}; + System.out.println("Array before sorting"); + printArray(arr); + + ShellSort ob = new ShellSort(); + ob.sort(arr); + + System.out.println("Array after sorting"); + printArray(arr); + } +}