Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ insert_tail(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                          inserttail(3C)



        _________________________________________________________________
        inserttail                                              function
        Insert an element at the tail of a queue.
        _________________________________________________________________


        Calling Sequence

        #include <queue.h>

        struct queue que;
        struct element *ptr;
        ptr = inserttail(&que, ptr);


        Description

        The insert_tail function inserts an element into the tail of a
        doubly-linked list.  You must define your element in the program.
        The first two double words of the element are reserved to hold
        the forward and backward pointers.  For example:

        struct element1 {
        int *forwardptr;
        int *backwardptr;
        char dataitem;
        } *ptr;

        The pointer that you pass to the insert_tail function is the
        pointer to the element that you define and declare in the
        program.

        The insert_tail function, defined in the include file queue.h,
        uses the hardware representation for queues. For more detail,
        consult The ECLIPSE 32-Bit Systems Principles of Operation.


        Returns

        The insert_tail function returns the pointer inserted.


        Related Functions

        See also the insert_head, insert_after, insert_before, and
        remove_tail functions.


        Example

        /* Program to demonstrate insert_tail and remove_tail  */



        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                          inserttail(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 links;             /* 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)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026