File tree 2 files changed +59
-42
lines changed
2 files changed +59
-42
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ struct Array
6
+ {
7
+ int * A;
8
+ int size;
9
+ int length;
10
+ };
11
+
12
+ void Display (struct Array * arr)
13
+ {
14
+ int i;
15
+ cout << " The elements of the array is " << endl;
16
+ for (i = 0 ; i < arr->length ; i++)
17
+ cout << arr->A [i] << " " ;
18
+ }
19
+
20
+ void ShellSort (struct Array * A, int n)
21
+ {
22
+ int gap, i, j, temp;
23
+
24
+ for (gap = n / 2 ; gap >= 1 ; gap /= 2 )
25
+ {
26
+ for (i = gap; i < n; i++)
27
+ {
28
+ temp = A->A [i];
29
+ j = i - gap;
30
+ while (j >= 0 && A->A [j] > temp)
31
+ {
32
+ A->A [j + gap] = A->A [j];
33
+ j = j - gap;
34
+ }
35
+ A->A [j + gap] = temp;
36
+
37
+ }
38
+ }
39
+
40
+ }
41
+
42
+ int main ()
43
+ {
44
+ struct Array arr;
45
+ cout << " Enter the size of the Array" << endl;
46
+ cin >> arr.size ;
47
+ arr.A = new int [arr.size ];
48
+ int no, i;
49
+ cout << " Enter the length of the Array " << endl;
50
+ cin >> no;
51
+ arr.length = 0 ;
52
+ cout << " Enter the elements of the Array" << endl;
53
+ for (i = 0 ; i < no; i++)
54
+ cin >> arr.A [i];
55
+ arr.length = no;
56
+ ShellSort (&arr,no);
57
+ Display (&arr);
58
+ return 0 ;
59
+ }
You can’t perform that action at this time.
0 commit comments