Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ remove_head(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                          removehead(3C)



        _________________________________________________________________
        removehead                                              function
        Delete an element from the head of a queue.
        _________________________________________________________________


        Calling Sequence

        #include <queue.h>

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


        Description

        The remove_head function removes an element from the head 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_head function is the
        pointer to the element that you define and declare in the
        program.

        The remove_head function uses the hardware representation for
        queues.  For more details, consult The ECLIPSE 32-Bit Systems
        Principles of Operation.


        Returns

        The remove_head function returns a pointer to the element.


        Related Functions

        See also the insert_head, remove_element, and remove_tail
        functions.


        Example

        /* Program to demonstrate insert_head and remove_head */



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





                                                          removehead(3C)



        /* functions.  This program reads lines from standard */
        /* input and inserts them at the head of the queue.   */
        /* After EOF, the program then removes elements from  */
        /* the head 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_head( &head, p_line );  /* add to head */
                }
                free( (char *) p_line );
        /* Now remove elements from head and print each element */
        while( (p_line = remove_head( &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