#include<stdio.h>
#include<stdlib.h>
/* Link list node */
struct node
{
int data;
struct node *next;
};
/* Function to reverse the linked list */
static void reverse(struct node** head_ref)
{
struct node *prev = NULL;
struct node *current = *head_ref;
struct node *next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head_ref = prev;
}
- What are the lines that start with struct in the reverse function responsible of?
do they extend the original struct or creating new structs that the original struct pointing to? I don’t really understand why there is no name to the original struct - Is there a diffrence between
struct node *next;andstruct node* next;?
Line
struct node *previs declaration of variableprevof type “pointer to struct node”. These lines just declare some local variables.prevcontains a pointer to the last processed node,currentcontains a pointer to the currently processing node andnextis used to save a pointer to the next node of original list.There’s no difference between
struct node *nextandstruct node* next.