insque.c 1.1 KB

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