-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
70 lines (59 loc) · 1.09 KB
/
utils.h
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
#include <stdio.h>
#include <stdlib.h>
void printArray(
int vector[],
int vector_length
){
/*Imprime sequancialmente os valores do vetor vector separado por um espaço
em uma única linha com uma quebra de linha no final.
*/
for(int i = 0; i < vector_length; i++){
printf("%d ", vector[i]);
}
printf("\n");
}
int randInt(
int a,
int b
){
/*Retorna um número aleatório contido no intervalo [a, b].
*/
int number;
int floor, roof;
if(a > b){
floor = b;
roof = a;
}else if(b > a){
floor = a;
roof = b;
}else{
return 0;
}
// srand(time(NULL));
return ((rand() % (roof-floor+1)) + floor);
}
void fillRandomVector(
int vector[],
int vector_length,
int start,
int end
){
/*Preenche um vetor de tamanho n com n números pseudo-aleatórios
de start até end.
*/
for(int i = 0; i < vector_length; i++){
vector[i] = randInt(start, end);
}
}
void copyVector(
int root[],
int destiny[],
int vectors_length
){
/*Copia de maneira sequencial os valores do vetor root para o
vetor destiny.
*/
for(int i = 0; i < vectors_length; i++){
destiny[i] = root[i];
}
}