Q:

Linked Lists - Global v. Local Variables

I have the following algorithm which is meant to reverse a linked list.
typedef struct node
{
    int data;
    struct node* next;
}LL_t;

void insert(LL_t** head, int value) 
{
    LL_t* new_node = (LL_t*) malloc(sizeof(LL_t)); 
    new_node->data  = value; 
    new_node->next = (*head); 
    (*head)    = new_node;
}

LL_t* head;
// Post: L contains the data in the original L, but in the reverse order.
void reverse(LL_t * L) {
    LL_t *current, *prev, *next;
    current = head;
    prev = NULL;
    while ( current != NULL )
    {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;  
    }   
    head = prev;
}

int main ()
{
struct node* L = NULL;
insert( &L, 42 );
insert( &L, 36 );
insert( &L, 14 );
insert( &L, 17 );
insert( &L, 48 );
insert( &L, 36 );

print(L);
printf("\n");
reverse(L);
print(L);

return 0;
}

The lists appear as identical when printed both before and after the reverse function. I believe that I have accidentally used local variables to modify my list, whereas I would like to directly modify the list (L). Output:
36 48 17 14 36 42
36 48 17 14 36 42

How does one directly modify a linked list using global variables?

A:

The problem with your code is you are passing the pointer by value to the function reverse and the pointer l is still pointing to the first element and not to the last element as you think after exiting from the reverse function ,you need to pass the pointer by reference and change the head of the list as shown below:
void reverse(LL_t **L) {
    LL_t *current, *prev, *next;
    current = *L;
    prev = NULL;
    while ( current != NULL )
    {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;  
    }
    head = prev;   
    *L = head;
}

call should be
reverse(&L);

Make this change and now call 
print(L) and see that you get a reversed linked-list.

If you have a fixed protoype like what you said in your comment then go for
void reverse(LL_t *L) {
    LL_t *current, *prev, *next;
    current = L;
    prev = NULL;
    while ( current != NULL )
    {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;  
    }   
    head = prev;
}

The call should be
reverse(L);

Then while printing call
print(head);

