-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellSort.cpp
More file actions
41 lines (33 loc) · 904 Bytes
/
ShellSort.cpp
File metadata and controls
41 lines (33 loc) · 904 Bytes
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
/**
* Author: Hemant Tripathi
*/
#include<iostream>
using namespace std;
#define MAXSIZE 8
int main() {
cout << "Starting program for Shell Sort" << endl;
int dataArray[] = {25, 57, 48, 37, 12, 92, 86, 33};
for(int gap = MAXSIZE/2; gap>0; gap = gap/2) {
cout << "Gap Size = "<<gap<<endl;
for(int i=gap; i < MAXSIZE; i++) {
int tmp = dataArray[i];
cout << "i = " << i << "; temp value = " << tmp << endl;
int j;
for (j=i; j >= gap && dataArray[j-gap] > tmp; j -=gap) {
dataArray[j] = dataArray[j-gap];
}
dataArray[j] = tmp;
}
cout << "After next iteration, Array is: ";
for(int x=0; x < MAXSIZE; x++) {
cout << "\t" << dataArray[x];
}
cout << endl;
}
cout << "################ Result #######################" << endl;
cout << "Shell Sorting done. Final Result: ";
for(int i=0; i < MAXSIZE; i++) {
cout << "\t" << dataArray[i];
}
cout << endl;
}