-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellsort.cpp
More file actions
46 lines (34 loc) · 1.14 KB
/
shellsort.cpp
File metadata and controls
46 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// shell Sort
#include<iostream>
#include<chrono>
using namespace std;
using namespace std::chrono;
// UTILITY FUNCTIONS
// Function to print an array
void printArray(int A[], int size){
for (int i = 0; i < size; i++)
cout << A[i] << " ";
}
void shellsort(int arr[], int n){
for (int gap = n/2; gap=>0; gap/=2){
for(int i = gap; j<=n; j++){
// TBD for(int j=i j>=gap )
}
}
}
int main(){
// int arr[] = {3,5,1,7,3,8};
int arr[] = {5,7,3,1,5,6,3,5,1,8,9,3,4,5,6,7,2,3,4,5,2,3,4,8,9,4,5,6,7,4,5,6,3,4,5,6,7,8,9,0,3,4,5,6,3,5,1,7,3,8,4,2,7,6,5,3,1,8,9,0,3,4,5,6,7,8,9,3,4,5,6,7,2,3,4,5,2,3,4,8,9,4,5,6,7,4,5,6,3,4,5,6,7,8,9,0,3,4,5,6};
int n = sizeof(arr)/sizeof(*arr);
cout << " size of input n "<< n << endl;
printArray(arr,n);
auto start = high_resolution_clock::now();
shellsort(arr, n);
auto stop = high_resolution_clock::now();
cout << "\nSorted array is \n";
printArray(arr, n);
auto duration = duration_cast<microseconds>(stop - start);
cout << "\n duration " << duration.count() << " ms " << endl;
}
// g++ -o shellsort.out shellsort.cpp
// ./shellsort.out