1 /* This software was developed by Bruce Hendrickson and Robert Leland *
2 * at Sandia National Laboratories under US Department of Energy *
3 * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
4
5 #include <stdio.h>
6 #include "structs.h"
7 #include "defs.h"
8
9
10 /* Note: bi-directional lists aren't assumed to be sorted. */
11
add2bilist(lptr,list)12 void add2bilist(lptr, list)/* add val to unsorted list */
13 struct bilist *lptr; /* element to add */
14 struct bilist **list; /* list added to */
15 {
16 lptr->next = *list;
17 if (*list != NULL)
18 (*list)->prev = lptr;
19 lptr->prev = NULL;
20 *list = lptr;
21 }
22
23
removebilist(lptr,list)24 void removebilist(lptr, list)
25 struct bilist *lptr; /* ptr to element to remove */
26 struct bilist **list; /* head of list to remove it from */
27
28 /* Remove an element from a bidirectional list. */
29 {
30 if (lptr->next != NULL)
31 lptr->next->prev = lptr->prev;
32 if (lptr->prev != NULL)
33 lptr->prev->next = lptr->next;
34 else
35 *list = lptr->next;
36 }
37
38
movebilist(lptr,oldlist,newlist)39 void movebilist(lptr, oldlist, newlist)
40 struct bilist *lptr; /* ptr to element to move */
41 struct bilist **oldlist; /* head of list to remove it from */
42 struct bilist **newlist; /* head of list to add it to */
43
44 /* Move an element from a old bidirectional list to new one. */
45 {
46 removebilist(lptr, oldlist);
47
48 add2bilist(lptr, newlist);
49 }
50