forked from rtinos/gpx2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_functions.cpp
More file actions
113 lines (91 loc) · 2.85 KB
/
util_functions.cpp
File metadata and controls
113 lines (91 loc) · 2.85 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/******************************************************************************\
* Diverse Functions *
\******************************************************************************/
#include "defs.h"
#include <cstdlib>
/******************************************************************************\
* Dynamic Allocation: Matrix of Integers *
\******************************************************************************/
int **aloc_matrixi(int lines , int collums)
{
int i, **Matrix;
Matrix = new int*[lines];
for (i=0;i<lines;i++) {
Matrix[i] = new int[collums];
}
if (!Matrix) {
cerr << "Allocation Error!" << endl;
exit(EXIT_FAILURE);
}
return Matrix;
}
/******************************************************************************\
* Dynamic Allocation: Vector of Integers *
\******************************************************************************/
int *aloc_vectori(int lines)
{
int *vector;
vector = new int[lines];
if (!vector) {
cerr << "Allocation Error!" << endl;
exit(EXIT_FAILURE);
}
return vector;
}
// Initialized to 0
int *aloc_vectori0(int lines)
{
int *vector;
vector = new int[lines]();
if (!vector) {
cerr << "Allocation Error!" << endl;
exit(EXIT_FAILURE);
}
return vector;
}
/******************************************************************************\
* Dynamic Allocation: Vector of Doubles *
\******************************************************************************/
double *aloc_vectord(int lines)
{
double *vector;
vector = new double[lines];
if (!vector) {
cout<<"Allocation Error!"<<endl;
exit(1);
}
return vector;
}
/******************************************************************************\
* Dynamic Desallocation: Matrix of Integers *
\******************************************************************************/
void desaloc_matrixi(int **Matrix , int lines)
{
int i;
for(i=0;i<lines;i++) {
delete [] Matrix[i];
}
delete [] Matrix;
}
/******************************************************************************\
* Real Random Number *
\******************************************************************************/
double rand_number(void)
{
return ( rand()/(RAND_MAX+1.0) );
}
/******************************************************************************\
* Random Permutation of a Vector of Integers *
* (using standard random generator) *
\******************************************************************************/
void rand_perm(int *inp, int *out, int size)
{
int i, j;
out[0]=inp[0];
for(i=1;i<size;i++) {
j= (int) ( rand_number() *(i-0.0)+0.0); // random integer beteween [lim_inf=0 , lim_sup=i]
if (i != j)
out[i]=out[j];
out[j]=inp[i];
}
}