-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathdebug.cpp
44 lines (37 loc) · 906 Bytes
/
debug.cpp
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
#include <algorithm>
#include <iostream>
void swap(int* a, int* b)
{
int c = *a;
*a = *b;
*b = c;
}
void reverse(int* v, unsigned int len)
{
for (unsigned int i = 0; i < (len + 1) / 2; i++) {
const int a = i;
const int b = len - i;
swap(v + a, v + b);
}
}
int* createAndFillVector(unsigned int len)
{
auto v = new int[len];
for (unsigned int i = 0; i < len; i++) {
v[i] = i;
}
return v;
}
int main()
{
constexpr auto arraySize = 100;
int* v = nullptr;
// create and reverse the vector of LEN numbers
v = createAndFillVector(arraySize);
reverse(v, arraySize);
// check if the revert worked:
const bool isReversed = std::is_sorted(v, v + arraySize, std::greater {});
std::cout << "Vector reversed successfully: " << std::boolalpha
<< isReversed << "\n";
return isReversed ? 0 : 1;
}