Mercurial > hg > th-libs
comparison th_datastruct.c @ 754:d91d1174cfd8
Add th_llist_reverse() for reversing a linked list.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 01 Feb 2023 13:02:35 +0200 |
parents | 64cb2b1777a9 |
children | 3f84521fdd31 |
comparison
equal
deleted
inserted
replaced
753:64cb2b1777a9 | 754:d91d1174cfd8 |
---|---|
220 | 220 |
221 return -1; | 221 return -1; |
222 } | 222 } |
223 | 223 |
224 | 224 |
225 void th_llist_reverse(th_llist_t **list) | |
226 { | |
227 th_llist_t *curr = *list, *prev = NULL; | |
228 | |
229 while (curr != NULL) | |
230 { | |
231 th_llist_t *next = curr->next; | |
232 curr->next = prev; | |
233 prev = curr; | |
234 curr = next; | |
235 if (curr != NULL) | |
236 curr->prev = prev; | |
237 } | |
238 | |
239 *list = prev; | |
240 } | |
241 | |
242 | |
225 void th_llist_foreach(th_llist_t *list, void (*func)(th_llist_t *node, void *userdata), void *data) | 243 void th_llist_foreach(th_llist_t *list, void (*func)(th_llist_t *node, void *userdata), void *data) |
226 { | 244 { |
227 th_llist_t *curr = list; | 245 th_llist_t *curr = list; |
228 | 246 |
229 while (curr != NULL) | 247 while (curr != NULL) |