File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < algorithm>
3
+ using namespace std ;
4
+
5
+ void swap (int * p, int * q){
6
+ int temp = * p;
7
+ * p = * q;
8
+ * q = temp;
9
+ }
10
+
11
+ void array_in_wave (int array[], int n){
12
+ sort (array, array + n);
13
+ for (int i = 0 ; i < n - 1 ; i += 2 )
14
+ swap ( & array[i], & array[i + 1 ]);
15
+ }
16
+
17
+ int main (){
18
+ int array[100 ], n, i;
19
+ cout << " Enter number of elements: " ;
20
+ cin >> n;
21
+ cout << " \n Enter elements: " ;
22
+
23
+ for (i = 0 ; i < n; i++)
24
+ cin >> array[i];
25
+
26
+ cout << " Original array: " ;
27
+
28
+ for (int i = 0 ; i < n; i++)
29
+ cout << array[i] << " " ;
30
+
31
+ array_in_wave (array, n);
32
+
33
+ cout << " \n Wave form of the array is: " ;
34
+
35
+ for (int i = 0 ; i < n; i++)
36
+ cout << array[i] << " " ;
37
+
38
+ return 0 ;
39
+ }
You can’t perform that action at this time.
0 commit comments