diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-02-23 14:09:26 -0500 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-02-23 15:00:17 -0500 |
commit | 995f7838c0d47b3f4974e8bf501daf1d1f5e247f (patch) | |
tree | c27d4a82784a52bbd7073409cacea6e7ab33dd98 | |
parent | c38089c8246d25f64557de6cf2542b48f91ace4c (diff) |
Add truncate function for double ended queue
-rw-r--r-- | collections/double_ended_queue.c | 11 | ||||
-rw-r--r-- | collections/double_ended_queue.h | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/collections/double_ended_queue.c b/collections/double_ended_queue.c index 6a3a810..1f18330 100644 --- a/collections/double_ended_queue.c +++ b/collections/double_ended_queue.c @@ -181,3 +181,14 @@ int i, j; root->end[j] = root->end[i]; root->end[i] = tmp; } + +void deq_truncate(root, size) +deq *root; +int size; +{ + if ((!root) || size > deq_size(root)) { + return; + } + + root->end = root->beg + size; +} diff --git a/collections/double_ended_queue.h b/collections/double_ended_queue.h index d1d687a..283d9c3 100644 --- a/collections/double_ended_queue.h +++ b/collections/double_ended_queue.h @@ -20,11 +20,11 @@ void* deq_index(deq*, int); void* deq_pop_back(deq*); void deq_swap(deq*, int, int); +void deq_truncate(deq*, int); /* * resevee - * truncate * front * back * push/pop front |