queue.c
/*
 * Reverse elements in queue
 * No effect if q is NULL or empty
 * This function should not allocate or free any list elements
 * (e.g., by calling q_insert_head, q_insert_tail, or q_remove_head).
 * It should rearrange the existing ones.
 */
Reverse elements in queue
No effect if q is NULL or empty
This function should not allocate or free any list elements
.
It should rearrange the existing ones.
Reverse elements in queue No effect if q is NULL or empty This function should not allocate or free any list elements . It should rearrange the existing ones .
void q_reverse(struct list_head *head)
{
    if (!head || head->next == head)
        return;
    struct list_head *node = head, *temp;
    head->prev->next = NULL;
    head->prev = NULL;
    while (1) {
        temp = node->next;
        node->next = node->prev;
        node->prev = temp;
        if (!node->prev)
            break;
        else
            node = node->prev;
    }
    node->prev = head;
    head->next = node;
}
void q_reverse ( struct list_head * head ) { if ( ! head || head -> next == head ) return ; struct list_head * node = head , * temp ; head -> prev -> next = NULL ; head -> prev = NULL ; while ( 1 ) { temp = node -> next ; node -> next = node -> prev ; node -> prev = temp ; if ( ! node -> prev ) break ; else node = node -> prev ; } node -> prev = head ; head -> next = node ; }
Reverse elements in queue
 No effect if q is NULL or empty
 This function should not allocate or free any list elements
 (e.g., by calling q_insert_head, q_insert_tail, or q_remove_head).
Reverse elements in queue No effect if q is NULL or empty This function should not allocate or free any list elements ( e . g . by calling q_insert_head q_insert_tail or q_remove_head ) .