Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | /* insque(3C) routines |
2 | This file is in the public domain. */ | |
3 | ||
4 | /* | |
252b5132 | 5 | |
d4d868a2 RW |
6 | @deftypefn Supplemental void insque (struct qelem *@var{elem}, @ |
7 | struct qelem *@var{pred}) | |
ba19b94f | 8 | @deftypefnx Supplemental void remque (struct qelem *@var{elem}) |
252b5132 | 9 | |
ba19b94f DD |
10 | Routines to manipulate queues built from doubly linked lists. The |
11 | @code{insque} routine inserts @var{elem} in the queue immediately | |
12 | after @var{pred}. The @code{remque} routine removes @var{elem} from | |
13 | its containing queue. These routines expect to be passed pointers to | |
14 | structures which have as their first members a forward pointer and a | |
15 | back pointer, like this prototype (although no prototype is provided): | |
252b5132 | 16 | |
ba19b94f DD |
17 | @example |
18 | struct qelem @{ | |
19 | struct qelem *q_forw; | |
20 | struct qelem *q_back; | |
21 | char q_data[]; | |
22 | @}; | |
23 | @end example | |
24 | ||
25 | @end deftypefn | |
252b5132 | 26 | |
252b5132 RH |
27 | */ |
28 | ||
29 | ||
30 | struct qelem { | |
31 | struct qelem *q_forw; | |
32 | struct qelem *q_back; | |
33 | }; | |
34 | ||
35 | ||
36 | void | |
49b1fae4 | 37 | insque (struct qelem *elem, struct qelem *pred) |
252b5132 RH |
38 | { |
39 | elem -> q_forw = pred -> q_forw; | |
40 | pred -> q_forw -> q_back = elem; | |
41 | elem -> q_back = pred; | |
42 | pred -> q_forw = elem; | |
43 | } | |
44 | ||
45 | ||
46 | void | |
49b1fae4 | 47 | remque (struct qelem *elem) |
252b5132 RH |
48 | { |
49 | elem -> q_forw -> q_back = elem -> q_back; | |
50 | elem -> q_back -> q_forw = elem -> q_forw; | |
51 | } |