-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl10.cpp
More file actions
46 lines (45 loc) · 893 Bytes
/
l10.cpp
File metadata and controls
46 lines (45 loc) · 893 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
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
void printArray(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
void swapAlternate(int *a, int n)
{
int i = 1;
int temp;
while (i < n)
{
cout << "reversing" << a[i - 1] << "and" << a[i] << endl;
temp = a[i - 1];
a[i - 1] = a[i];
a[i] = temp;
i = i + 2;
}
cout << "printing array after operation" << endl;
for (int i = 0; i < n; i++)
{
cout << a[i] << endl;
}
}
void swapalternateBabbar(int arr[], int size)
{
for (int i = 0; i < size; i += 2)
{
if (i + 1 < size)
{
swap(arr[i], arr[i + 1]);
}
}
}
int main()
{
int even[8] = {5, 2, 9, 4, 7, 6, 1, 0};
int odd[5] = { 11, 23, 9, 76, 4};
swapalternateBabbar(even, 8);
printArray(even, 8);
}