I am creating three nodes in linked list
Code:
#include<stdio.h>#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
int main()
{
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
struct Node *temp = NULL;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
head->data = 1; //assign data in first node
head->next = second; // Link first node with second
second->data = 2; //assign data to second node
second->next = third;
third->data = 3; //assign data to third node
third->next = NULL;
temp = head;
while (temp != NULL)
{
printf(" %d ", temp->data);
temp = temp->next;
}
return 0;
}
I want to create function that would add new node and return the reference
Code:
int New_Node( int data){
// make a new node and return the reference
}
How to create new node and return the reference in function ?