diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/evalexpr/dlist/dlist-3.c | |
add: graphs et rushs
Diffstat (limited to 'rushs/evalexpr/dlist/dlist-3.c')
| -rw-r--r-- | rushs/evalexpr/dlist/dlist-3.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/rushs/evalexpr/dlist/dlist-3.c b/rushs/evalexpr/dlist/dlist-3.c new file mode 100644 index 0000000..22b4b52 --- /dev/null +++ b/rushs/evalexpr/dlist/dlist-3.c @@ -0,0 +1,83 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "dlist.h" + +void dlist_map_square(struct dlist *list) +{ + for (struct dlist_item *i = list->head; i; i = i->next) + { + i->data *= i->data; + } +} + +void dlist_reverse(struct dlist *list) +{ + struct dlist_item *tmp; + for (struct dlist_item *i = list->head; i; i = i->prev) + { + tmp = i->next; + i->next = i->prev; + i->prev = tmp; + } + tmp = list->tail; + list->tail = list->head; + list->head = tmp; +} + +struct dlist *dlist_split_at(struct dlist *list, size_t index) +{ + if (list->size == 0) + return dlist_init(); + if (index >= list->size) + { + return NULL; + } + + struct dlist *new = dlist_init(); + if (new == NULL) + return NULL; + new->size = list->size - index; + list->size = index; + + struct dlist_item *i; + for (i = list->head; index; index--, i = i->next) + { + continue; + } + + new->head = i; + new->tail = list->tail; + list->tail = i->prev; + if (i->prev) + { + i->prev->next = NULL; + } + else + { + list->head = NULL; + } + i->prev = NULL; + return new; +} + +void dlist_concat(struct dlist *list1, struct dlist *list2) +{ + if (list2->head == NULL) + return; + if (list1->tail == NULL) + { + list1->head = list2->head; + list1->tail = list2->tail; + list1->size = list2->size; + return; + } + + list1->tail->next = list2->head; + list2->head->prev = list1->tail; + list1->tail = list2->tail; + list1->size += list2->size; + list2->size = 0; + list2->head = NULL; + list2->tail = NULL; +} |
