File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ // /////////////////////////////////////////////////////////////////////////////////
2
+ // Name :Manasi Mohan Wader. //
3
+ // Program :Shell Sort. //
4
+ // Approach :Using Array. //
5
+ // Language :C++ //
6
+ // Functions:To perform ascending sorting of elements. // //
7
+ // /////////////////////////////////////////////////////////////////////////////////
8
+
9
+ #include < iostream>
10
+ #define MAX 30
11
+ using namespace std ;
12
+
13
+ // /////////////////////////////////////////////////////////////////////////////////
14
+ void ShellSort (int arr[],int size)
15
+ {
16
+ for (int gap=size/2 ;gap>=1 ;gap=gap/2 )
17
+ {
18
+ for (int j=gap;j<size;j++)
19
+ {
20
+ for (int i=j-gap;i>=0 ;i=i-gap)
21
+ {
22
+ if (arr[i]<arr[i+gap])
23
+ break ;
24
+ else
25
+ {
26
+ int temp;
27
+ temp=arr[i];
28
+ arr[i]=arr[i+gap];
29
+ arr[i+gap]=temp;
30
+ }
31
+
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ // /////////////////////////////////////////////////////////////////////////////////
38
+ int main ()
39
+ {
40
+ int size;
41
+ int arr[MAX];
42
+ cin>>size;
43
+ for (int i=0 ;i<size;i++)
44
+ {
45
+ cin>>arr[i];
46
+ }
47
+ cout<<" \n Initial Array : " ;
48
+ for (int i=0 ;i<size;i++)
49
+ cout<<arr[i]<<" " ;
50
+ ShellSort (arr,size);
51
+ cout<<" \n Sorted Array : " ;
52
+ for (int i=0 ;i<size;i++)
53
+ cout<<arr[i]<<" " ;
54
+ return 0 ;
55
+ }
56
+
57
+ // /////////////////////////////////////////////////////////////////////////////////
58
+ // End of code
59
+ // /////////////////////////////////////////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments