remque(3C)
_________________________________________________________________
remque function
Remove an element from a circular queue.
_________________________________________________________________
Calling Sequence
struct qelem {
struct qelem *qforw;
struct qelem *qback;
/* User data follows */
} *elem;
int remque();
remque(elem);
where elem is a pointer to the structure to remove from a
linked list.
Description
The remque function removes an element from a circular linked
list; this function comes from the University of California
Berkeley UNIX (BSD) system.
The structures in the linked list must reserve the first two
double words for use as the forward and backward pointers. Since
the linked list is a circular list, the initial element must have
forward and backward links to itself.
Returns
The remque function does not return a value.
Related Functions
See also the insque function.
Example
This program reads lines from standard input, creates a linked
list, removes elements from the list with remque, and prints the
elements.
/* Program test for the remque() function */
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
remque(3C)
#include <stdio.h>
#define LSIZE 256 /* line size */
extern char *malloc();
extern int insque(), remque();
extern void free();
struct qelem {
struct qelem *q_forw; /* forward link */
struct qelem *q_back; /* backward link */
char buffer[LSIZE]; /* line buffer */
};
struct qelem head = {&head, &head}; /* head of queue */
struct qelem *p_last = &head; /* last item */
struct qelem *p_line; /* ptr to walk list */
struct qelem *p_next; /* next item in list */
main() {
for (;;) {
p_line = (struct qelem *)
malloc(sizeof(struct qelem));
if (p_line == (struct qelem *)0) {
printf("Out of memory.\n");
exit(1);
}
if (!fgets(p_line -> buffer, LSIZE, stdin))
break; /* End of file found */
(void) insque(p_line, p_last);
p_last = p_line;
}
free((char *)p_line);
/* Now walk list and print elements */
for (p_line = head.q_forw; p_line != &head;
p_line = p_next) {
p_next = p_line -> q_forw;
(void) remque(p_line);
fputs(p_line -> buffer, stdout);
free((char *)p_line);
}
return 0;
}
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)