| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "structs.h" // for bilist |
| 10 |
#include <stdio.h> // for NULL |
| 11 |
|
| 12 |
/* Note: bi-directional lists aren't assumed to be sorted. */ |
| 13 |
|
| 14 |
void add2bilist( /* add val to unsorted list */ |
| 15 |
struct bilist *lptr, /* element to add */ |
| 16 |
struct bilist **list /* list added to */ |
| 17 |
) |
| 18 |
{ |
| 19 |
lptr->next = *list; |
| 20 |
if (*list != NULL) { |
| 21 |
(*list)->prev = lptr; |
| 22 |
} |
| 23 |
lptr->prev = NULL; |
| 24 |
*list = lptr; |
| 25 |
} |
| 26 |
|
| 27 |
void removebilist(struct bilist *lptr, /* ptr to element to remove */ |
| 28 |
struct bilist **list /* head of list to remove it from */ |
| 29 |
) |
| 30 |
|
| 31 |
/* Remove an element from a bidirectional list. */ |
| 32 |
{ |
| 33 |
if (lptr->next != NULL) { |
| 34 |
lptr->next->prev = lptr->prev; |
| 35 |
} |
| 36 |
if (lptr->prev != NULL) { |
| 37 |
lptr->prev->next = lptr->next; |
| 38 |
} |
| 39 |
else { |
| 40 |
*list = lptr->next; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
void movebilist(struct bilist *lptr, /* ptr to element to move */ |
| 45 |
struct bilist **oldlist, /* head of list to remove it from */ |
| 46 |
struct bilist **newlist /* head of list to add it to */ |
| 47 |
) |
| 48 |
|
| 49 |
/* Move an element from a old bidirectional list to new one. */ |
| 50 |
{ |
| 51 |
removebilist(lptr, oldlist); |
| 52 |
|
| 53 |
add2bilist(lptr, newlist); |
| 54 |
} |