I am looking help to change function in my code. currently function create node, assign data to node but it doesn't link node to next node in list
Code:
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *nextNode;
};
void addNode(int value )
{
struct node *newNode = NULL;
newNode = malloc (sizeof(*newNode));
if (newNode != NULL)
{
newNode -> data = value;
newNode -> nextNode = NULL;
}
}
int main()
{
addNode( 2 );
return 0;
}
I know This line doesn't point to address of next node
Code:
newNode -> nextNode = NULL;
can anyone explain theoritically what I need to link next node in linked list ?