shell sort in c 2b 2b

Solutions on MaxInterview for shell sort in c 2b 2b by the best coders in the world

showing results for - " shell sort in c 2b 2b"
Erica
29 Oct 2016
1#include  <iostream> 
2using namespace std; 
3  
4
5int shellSort(int arr[], int n) 
6{ 
7
8    for (int gap = n/2; gap > 0; gap /= 2) 
9    { 
10          
11        for (int i = gap; i < n; i += 1) 
12        { 
13           
14            int temp = arr[i]; 
15  
16           
17            int j;             
18            for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) 
19                arr[j] = arr[j - gap]; 
20              
21            
22            arr[j] = temp; 
23        } 
24    } 
25    return 0; 
26} 
27  
28void printArray(int arr[], int n) 
29{ 
30    for (int i=0; i<n; i++) 
31        cout << arr[i] << " "; 
32} 
33  
34int main() 
35{ 
36    int arr[] = {12, 34, 54, 2, 3}, i; 
37    int n = sizeof(arr)/sizeof(arr[0]); 
38  
39    cout << "Array before sorting: \n"; 
40    printArray(arr, n); 
41  
42    shellSort(arr, n); 
43  
44    cout << "\nArray after sorting: \n"; 
45    printArray(arr, n); 
46  
47    return 0;
48}
Kash
03 Aug 2020
105,04,09,19,15,14,10,15,20,01
Javier
26 Jan 2021
105,04,09,19,15,14,10,15,20,01