Hello,
I am trying to understand this program.
Code:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node* AddToFront (struct node *head, int value)
{
struct node *new = malloc(sizeof(*new));
if ( new != NULL)
{
new -> data = value ;
new -> next = head;
}
return new;
}
void show (struct node *head)
{
struct node *current;
current = head;
while (current != NULL)
{
printf("%d\n", current -> data);
current = current -> next;
}
}
int main ()
{
struct node *head = NULL;
head = AddToFront( head, 1 );
head = AddToFront( head, 2 );
head = AddToFront( head, 3 );
show (head);
return 0;
}
I don't understand how does function show work in program
function takes value of head pointer
current is structured pointer which is declered inside function
value of head pointer being assigned to current structure pointer
after that it's being checked that current is not null
Code:
void show (struct node *head){
struct node *current;
current = head;
while (current != NULL)
{
printf("%d\n", current -> data);
current = current -> next;
}
}
I don't understand two statement inside while loop
I don't understand what does it mean current -> data
I don't understand what does it mean current = current -> next;