insque - Online Linux Manual PageSection : 3
Updated : 2023-02-05
Source : Linux man-pages 6.03

NAMEinsque, remque − insert/remove an item from a queue

LIBRARYStandard C library (libc, −lc)

SYNOPSIS#include <search.h>void insque(void *elem, void *prev); void remque(void *elem);Feature Test Macro Requirements for glibc (see feature_test_macros(7)): insque(), remque(): _XOPEN_SOURCE >= 500 || /* glibc >= 2.19: */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _SVID_SOURCE

DESCRIPTIONThe insque() and remque() functions manipulate doubly linked lists. Each element in the list is a structure of which the first two elements are a forward and a backward pointer. The linked list may be linear (i.e., NULL forward pointer at the end of the list and NULL backward pointer at the start of the list) or circular. The insque() function inserts the element pointed to by elem immediately after the element pointed to by prev. If the list is linear, then the call insque(elem, NULL)" can be used to insert the initial list element, and the call sets the forward and backward pointers of elem to NULL. If the list is circular, the caller should ensure that the forward and backward pointers of the first element are initialized to point to that element, and the prev argument of the insque() call should also point to the element. The remque() function removes the element pointed to by elem from the doubly linked list.

ATTRIBUTESFor an explanation of the terms used in this section, see attributes(7). InterfaceAttributeValue insque(), remque() Thread safetyMT-Safe

STANDARDSPOSIX.1-2001, POSIX.1-2008.

NOTESOn ancient systems, the arguments of these functions were of type struct qelem *, defined as: struct qelem { struct qelem *q_forw; struct qelem *q_back; char q_data[1]; };This is still what you will get if _GNU_SOURCE is defined before including <search.h>. The location of the prototypes for these functions differs among several versions of UNIX. The above is the POSIX version. Some systems place them in <string.h>.

BUGSIn glibc 2.4 and earlier, it was not possible to specify prev as NULL. Consequently, to build a linear list, the caller had to build a list using an initial call that contained the first two elements of the list, with the forward and backward pointers in each element suitably initialized.

EXAMPLESThe program below demonstrates the use of insque(). Here is an example run of the program: $ ./a.out −c a b c Traversing completed list: a b c That was a circular list

Program source#include <search.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> struct element { struct element *forward; struct element *backward; char *name; }; static struct element * new_element(void) { struct element *e; e = malloc(sizeof(*e)); if (e == NULL) { fprintf(stderr, "malloc() failed\n"); exit(EXIT_FAILURE); } return e; } int main(int argc, char *argv[]) { struct element *first, *elem, *prev; int circular, opt, errfnd; /* The "−c" command−line option can be used to specify that the list is circular. */ errfnd = 0; circular = 0; while ((opt = getopt(argc, argv, "c")) != −1) { switch (opt) { case 'c': circular = 1; break; default: errfnd = 1; break; } } if (errfnd || optind >= argc) { fprintf(stderr, "Usage: %s [−c] string...\n", argv[0]); exit(EXIT_FAILURE); } /* Create first element and place it in the linked list. */ elem = new_element(); first = elem; elem−>name = argv[optind]; if (circular) { elem−>forward = elem; elem−>backward = elem; insque(elem, elem); } else { insque(elem, NULL); } /* Add remaining command−line arguments as list elements. */ while (++optind < argc) { prev = elem; elem = new_element(); elem−>name = argv[optind]; insque(elem, prev); } /* Traverse the list from the start, printing element names. */ printf("Traversing completed list:\n"); elem = first; do { printf(" %s\n", elem−>name); elem = elem−>forward; } while (elem != NULL && elem != first); if (elem == first) printf("That was a circular list\n"); exit(EXIT_SUCCESS); }

SEE ALSOqueue(7)
0
Johanes Gumabo
Data Size   :   16,519 byte
man-remque.3Build   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   3 / 202,854
Visitor ID   :     :  
Visitor IP   :   3.15.15.91   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.