removetail(3C)
_________________________________________________________________
removetail function
Delete an element from the tail of a queue.
_________________________________________________________________
Calling Sequence
#include <queue.h>
struct queue que;
struct element *ptr, removetail();
ptr = removetail(&que);
Description
The remove_tail function removes an element from the tail of a
doubly-linked list. Define the element in your program. The
first two double words of the element are reserved to hold
forward and backward pointers. For example:
struct element2 {
int *forwardptr;
int *backwardptr;
char item;
} *ptr;
The pointer that you pass to the remove_tail function is the
pointer to the element that you define and declare in the
program.
The remove_tail function uses the hardware representation for
queues. For more details, consult The ECLIPSE Systems Principles
of Operation.
Returns
The function returns a pointer to the element.
Related Functions
See also the insert_tail, remove_element, and remove_head
functions.
Example
/* Program to demonstrate insert_tail and remove_tail */
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
removetail(3C)
/* functions. This program reads lines from standard */
/* input and inserts them at the tail of the queue. */
/* After EOF, the program then removes elements from */
/* the tail and prints them, effectively reversing */
/* the input lines. */
#include <stdio.h>
#include <queue.h>
char *malloc();
#define LSIZE 256 /* line size */
struct line {
struct element lin1s; /* forward/backward links */
char buffer[LSIZE]; /* line buffer */
} *p_line;
struct queue head = {QNULL, QNULL}; /* head/tail of queue */
main() {
for(;;) {
p_line = (struct line *)malloc(sizeof(struct line));
if( p_line == (struct line *)0) {
printf("Out of memory.\n");
exit(1);
}
if (dg_fgets(p_line -> buffer, LSIZE, stdin) == (char)0)
break; /* end of file found */
(void) insert_tail(&head, p_line); /* add to tail */
}
free((char *)p_line);
/* Now remove elements from tail and print each element */
while ((p_line = remove_tail(&head)) != (struct line *)0) {
fputs(p_line -> buffer, stdout);
free((char *)p_line);
}
exit(0);
}
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)