diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-30 19:07:43 -0600 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-30 19:07:43 -0600 |
commit | 562ba9a9b6efd8cc27fc506f83b1125c2cfa4619 (patch) | |
tree | f801276f9332462084966ee731e2e90c0f180cb2 /src/vector.c | |
parent | 81979f09cf100db32deb0e1917dabb1fe435194c (diff) | |
download | cmath-562ba9a9b6efd8cc27fc506f83b1125c2cfa4619.tar.gz cmath-562ba9a9b6efd8cc27fc506f83b1125c2cfa4619.zip |
hw 5
Diffstat (limited to 'src/vector.c')
-rw-r--r-- | src/vector.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/vector.c b/src/vector.c index 3e4f62d..1b3e0b0 100644 --- a/src/vector.c +++ b/src/vector.c @@ -88,6 +88,21 @@ Array_double *copy_vector(Array_double *v) { return copy; } +Array_double *add_element(Array_double *v, double x) { + Array_double *pushed = InitArrayWithSize(double, v->size + 1, 0.0); + for (size_t i = 0; i < v->size; ++i) + pushed->data[i] = v->data[i]; + pushed->data[v->size] = x; + return pushed; +} + +Array_double *slice_element(Array_double *v, size_t x) { + Array_double *sliced = InitArrayWithSize(double, v->size - 1, 0.0); + for (size_t i = 0; i < v->size - 1; ++i) + sliced->data[i] = i >= x ? v->data[i + 1] : v->data[i]; + return sliced; +} + void free_vector(Array_double *v) { free(v->data); free(v); |