diff options
| author | Louis Burda <quent.burda@gmail.com> | 2021-12-04 13:48:01 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2021-12-20 15:31:16 +0100 |
| commit | 9fe644f0d99375ffd3011d8828f7dbd0fb103af0 (patch) | |
| tree | 71ed89f1c7316dba818bc921d772aaa1fc957dab /link.c | |
| parent | d68d0f39ab7675745e7d177f6774736f7ec58783 (diff) | |
| download | tmus-9fe644f0d99375ffd3011d8828f7dbd0fb103af0.tar.gz tmus-9fe644f0d99375ffd3011d8828f7dbd0fb103af0.zip | |
Added more gui interaction
Diffstat (limited to 'link.c')
| -rw-r--r-- | link.c | 64 |
1 files changed, 55 insertions, 9 deletions
@@ -1,30 +1,50 @@ #include "link.h" +#include "util.h" int -list_len(struct link *list) +list_len(struct link *head) { struct link *iter; int len; + ASSERT(head != NULL); + len = 0; - for (iter = list; iter; iter = iter->next) + for (iter = head->next; iter; iter = iter->next) len += 1; return len; } +int +list_ffind(struct link *head, struct link *link) +{ + struct link *iter; + + ASSERT(head != NULL); + + for (iter = head->next; iter && iter != link; iter = iter->next); + + return (iter == link); +} + struct link * -list_back(struct link *link) +link_back(struct link *link) { + ASSERT(link != NULL); + for (; link->next; link = link->next); + return link; } void -link_prepend(struct link *list, struct link *link) +link_prepend(struct link *cur, struct link *link) { - link->prev = list->prev; - link->next = list; + ASSERT(cur != NULL && link != NULL); + + link->prev = cur->prev; + link->next = cur; if (link->prev) link->prev->next = link; @@ -33,10 +53,12 @@ link_prepend(struct link *list, struct link *link) } void -link_append(struct link *list, struct link *link) +link_append(struct link *cur, struct link *link) { - link->prev = list; - link->next = list->next; + ASSERT(cur != NULL && link != NULL); + + link->prev = cur; + link->next = cur->next; if (link->prev) link->prev->next = link; @@ -47,8 +69,32 @@ link_append(struct link *list, struct link *link) void link_pop(struct link *link) { + ASSERT(link != NULL); + if (link->prev) link->prev->next = link->next; if (link->next) link->next->prev = link->prev; } + +struct link * +link_iter(struct link *link, int n) +{ + int i; + + for (i = 0; i < n; i++) { + if (!link) return NULL; + link = link->next; + } + + return link; +} + +void +link_push_back(struct link *cur, struct link *link) +{ + struct link *back; + + back = link_back(cur); + link_append(back, link); +} |
