We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1ec974a + 0579fb4 commit ced8a56Copy full SHA for ced8a56
SortInWaveForm.cpp
@@ -0,0 +1,39 @@
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 << "\nEnter 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 << "\nWave form of the array is: ";
34
35
36
37
38
+ return 0;
39
0 commit comments