Back to index

cell-binutils  2.17cvs20070401
insque.c
Go to the documentation of this file.
00001 /* insque(3C) routines
00002    This file is in the public domain.  */
00003 
00004 /*
00005 
00006 @deftypefn Supplemental void insque (struct qelem *@var{elem}, struct qelem *@var{pred})
00007 @deftypefnx Supplemental void remque (struct qelem *@var{elem})
00008 
00009 Routines to manipulate queues built from doubly linked lists.  The
00010 @code{insque} routine inserts @var{elem} in the queue immediately
00011 after @var{pred}.  The @code{remque} routine removes @var{elem} from
00012 its containing queue.  These routines expect to be passed pointers to
00013 structures which have as their first members a forward pointer and a
00014 back pointer, like this prototype (although no prototype is provided):
00015 
00016 @example
00017 struct qelem @{
00018   struct qelem *q_forw;
00019   struct qelem *q_back;
00020   char q_data[];
00021 @};
00022 @end example
00023 
00024 @end deftypefn
00025 
00026 */
00027 
00028 
00029 struct qelem {
00030   struct qelem *q_forw;
00031   struct qelem *q_back;
00032 };
00033 
00034 
00035 void
00036 insque (struct qelem *elem, struct qelem *pred)
00037 {
00038   elem -> q_forw = pred -> q_forw;
00039   pred -> q_forw -> q_back = elem;
00040   elem -> q_back = pred;
00041   pred -> q_forw = elem;
00042 }
00043 
00044 
00045 void
00046 remque (struct qelem *elem)
00047 {
00048   elem -> q_forw -> q_back = elem -> q_back;
00049   elem -> q_back -> q_forw = elem -> q_forw;
00050 }