-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayExpander.cpp
More file actions
61 lines (48 loc) · 1.21 KB
/
ArrayExpander.cpp
File metadata and controls
61 lines (48 loc) · 1.21 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
#include <iostream>
#include <random>
using namespace std;
float* arrayExpander(float* , short);
float* getSample(short);
int main(){
short size = arc4random_uniform(101);
float* sample = getSample(size);
for(short index = 0; index < size; index++){
cout << *(sample + index) << " ";
}
sample = arrayExpander(sample, size);
cout << "\n\n";
for(short index = 0; index < size*2; index++){
cout << *(sample + index) << " ";
}
delete[] sample;
sample = nullptr;
return 0;
}
/**
* @brief expands the array by double the size
*
* @param array
* @param size
* @return float*
*/
float* arrayExpander(float* array, short size){
float* biggerArray = new float[size*2];
for(short index = 0; index < size; index++)
*(biggerArray + index) = *(array + index);
for(short index = size; index < size*2; index++)
*(biggerArray + index) = 0;
return biggerArray;
}
/**
* @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;
}