diff --git a/Sorting/shell sort.cpp b/Sorting/shell sort.cpp new file mode 100644 index 0000000..86f4aa9 --- /dev/null +++ b/Sorting/shell sort.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; +void swap(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +void printArray(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 + swap(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: "; + printArray(arr, n); + shellSort(arr, n); + cout << "Array after Sorting: "; + printArray(arr, n); +}