From a40b11bd8b91f6a619a4af817e6d303502e071d4 Mon Sep 17 00:00:00 2001 From: avishi-bafna <56825730+avishi-bafna@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:52:29 +0530 Subject: [PATCH] Create shellSort.cpp --- C++ STL/shellSort.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 C++ STL/shellSort.cpp diff --git a/C++ STL/shellSort.cpp b/C++ STL/shellSort.cpp new file mode 100644 index 00000000..2c6533eb --- /dev/null +++ b/C++ STL/shellSort.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +void swapping(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i 0; gap = gap / 2) { + for(j = gap; j=0; k -= gap) { + if(arr[k+gap] >= arr[k]) + break; + else + swapping(arr[k+gap], arr[k]); + } + } + } +} +int main() { + int n; + cout << "Enter the number of elements: "; + cin >> n; + int arr[n]; + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + shellSort(arr, n); + cout << "Array after Sorting: "; + display(arr, n); +}