-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_wave.cpp
More file actions
36 lines (30 loc) · 778 Bytes
/
Copy patharray_wave.cpp
File metadata and controls
36 lines (30 loc) · 778 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
#include <iostream>
#include <algorithm> // For sorting
using namespace std;
int main() {
int array[] = {10, 49, 2, 1, 5, 23};
int n = sizeof(array) / sizeof(array[0]);
int temp;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (array[i] > array[j]) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
for (int i = 0; i < n; i = i + 2) {
if (i < n - 1) {
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
}
cout << "Array in Waveform Pattern: ";
for (int i = 0; i < n; i++) {
cout << array[i] << " ";
}
cout << endl;
return 0;
}