queue.c
/*
 * Attempt to insert element at head of queue.
 * Return true if successful.
 * Return false if q is NULL or could not allocate space.
 * Argument s points to the string to be stored.
 * The function must explicitly allocate space and copy the string into it.
 */
Attempt to insert element at head of queue.
Return true if successful.
Return false if q is NULL or could not allocate space.
Argument s points to the string to be stored.
The function must explicitly allocate space and copy the string into it.
Attempt to insert element at head of queue . Return true if successful . Return false if q is NULL or could not allocate space . Argument s points to the string to be stored . The function must explicitly allocate space and copy the string into it .
bool q_insert_head(struct list_head *head, char *s)
{
    if (!head || !s)
        return false;
    element_t *new = malloc(sizeof(element_t));
    if (!new)
        return false;
    else {
        new->value = strdup(s);
        if (!new->value) {
            free(new);
            return false;
        } else {
            list_add(&new->list, head);
            return true;
        }
    }
}
bool q_insert_head ( struct list_head * head , char * s ) { if ( ! head || ! s ) return false ; element_t * new = malloc ( sizeof ( element_t ) ) ; if ( ! new ) return false ; else { new -> value = strdup ( s ) ; if ( ! new -> value ) { free ( new ) ; return false ; } else { list_add ( & new -> list , head ) ; return true ; } } }
Attempt to insert element at head of queue.
Attempt to insert element at head of queue .