133965Sjdp/* insque(3C) routines
233965Sjdp   This file is in the public domain.  */
333965Sjdp
433965Sjdp/*
533965Sjdp
689857Sobrien@deftypefn Supplemental void insque (struct qelem *@var{elem}, struct qelem *@var{pred})
789857Sobrien@deftypefnx Supplemental void remque (struct qelem *@var{elem})
833965Sjdp
989857SobrienRoutines to manipulate queues built from doubly linked lists.  The
1089857Sobrien@code{insque} routine inserts @var{elem} in the queue immediately
1189857Sobrienafter @var{pred}.  The @code{remque} routine removes @var{elem} from
1289857Sobrienits containing queue.  These routines expect to be passed pointers to
1389857Sobrienstructures which have as their first members a forward pointer and a
1489857Sobrienback pointer, like this prototype (although no prototype is provided):
1533965Sjdp
1689857Sobrien@example
1789857Sobrienstruct qelem @{
1889857Sobrien  struct qelem *q_forw;
1989857Sobrien  struct qelem *q_back;
2089857Sobrien  char q_data[];
2189857Sobrien@};
2289857Sobrien@end example
2333965Sjdp
2489857Sobrien@end deftypefn
2589857Sobrien
2633965Sjdp*/
2733965Sjdp
2833965Sjdp
2933965Sjdpstruct qelem {
3033965Sjdp  struct qelem *q_forw;
3133965Sjdp  struct qelem *q_back;
3233965Sjdp};
3333965Sjdp
3433965Sjdp
3533965Sjdpvoid
36218822Sdiminsque (struct qelem *elem, struct qelem *pred)
3733965Sjdp{
3833965Sjdp  elem -> q_forw = pred -> q_forw;
3933965Sjdp  pred -> q_forw -> q_back = elem;
4033965Sjdp  elem -> q_back = pred;
4133965Sjdp  pred -> q_forw = elem;
4233965Sjdp}
4333965Sjdp
4433965Sjdp
4533965Sjdpvoid
46218822Sdimremque (struct qelem *elem)
4733965Sjdp{
4833965Sjdp  elem -> q_forw -> q_back = elem -> q_back;
4933965Sjdp  elem -> q_back -> q_forw = elem -> q_forw;
5033965Sjdp}
51