-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseArray.cpp
More file actions
64 lines (51 loc) · 1.23 KB
/
ReverseArray.cpp
File metadata and controls
64 lines (51 loc) · 1.23 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;
float* getSample(short);
float* reverseArray(float[], short);
int main(){
srand(time(0));
short size = arc4random_uniform(101);
float* sample = getSample(size);
cout << "\n";
for(short index = 0; index < size; index++)
cout << *(sample + index) << " ";
cout << "\n\n";
sample = reverseArray(sample, size);
for(short index = 0; index < size; index++)
cout << *(sample + index) << " ";
cout << "\n\n";
delete[] sample;
sample = nullptr;
return 0;
}
/**
* @brief Gets the reverse of the given array
*
* @param array
* @param size
* @return float*
*/
float* reverseArray(float array[], short size){
vector<float> list(array, array + size);
reverse(list.begin(), list.end());
for(short index = 0; index < size; index++)
array[index]= list[index];
return array;
}
/**
* @brief Get the Sample object
*
* @param size
* @return float*
*/
float* getSample(short size){
float* sample = new float[size];
for(short index = 0; index < size; index++){
sample[index] = arc4random_uniform(101);
}
return sample;
}