-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharr_oper.c
69 lines (54 loc) · 1.41 KB
/
arr_oper.c
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
#include <stdlib.h>
#include "arr_oper.h"
#define OK 0
#define REALLOC_ERR 7
#define EPS 1e-9
void *memory_changer(double *const *const arr, const short int new_n, short int *const code_err, double **const arr_end)
{
double *new_arr = NULL;
new_arr = realloc(*arr, new_n * sizeof(double));
if (new_arr == NULL)
{
*code_err = REALLOC_ERR;
return *arr;
}
*arr_end = new_arr + new_n;
*code_err = OK;
return new_arr;
}
static void del_by_pos(double *const arr_end, double *const pos)
{
for (double *i = pos; i < arr_end - 1; i++)
{
*i = *(i + 1);
}
}
void *del_from_arr(double *const arr, double *arr_end, const double num1, short int *const n)
{
for (double *i = arr; i < arr_end; i++)
{
if (num1 + EPS < *i)
{
del_by_pos(arr_end, i);
--i;
--arr_end;
}
}
*n = arr_end - arr;
return arr_end;
}
static void *add_by_pos(double *const arr, double *arr_end, double *const pos, const double added_numb)
{
for (double *i = arr_end - 1; i >= pos; i--)
{
*(i + 1) = *i;
}
*pos = added_numb;
return ++arr_end;
}
void add_to_arr(double *arr, double *arr_end, double *const pos, const double num2)
{
arr_end = add_by_pos(arr, arr_end, pos, num2);
arr_end = add_by_pos(arr, arr_end, arr, num2);
arr_end = add_by_pos(arr, arr_end, arr_end, num2);
}