C Program to Insert a Node at the Beginning of Linked List

Write a C program to insert a node at the beginning of linked list. In this tutorial, we create a linked list and insert a new node at the beginning/head of linked list.

A Linked list is a linear data structure which consists a group of nodes and each node points to next node by means of a pointer. In Linked list, a node consists of two parts, a data and a pointer to next node.

Algorithm to insert node at the beginning of a linked list

1. Create a new node dynamically (by allocating a memory).

2. Insert a data and point the new node to the next node.

3. Put a reference of head node to the new node. So that head node points to a new node.

Subscribe Our Tutorials

Get Latest Updates on Facebook

Insert Node at the Beginning of Linked List

Insert Node at the Beginning of Linked List

C Program to Insert a Node at the Beginning of Linked List

We have discussed, what is linked list? and algorithm to insert a node at the beginning of linked list. Let’s write a code to insert a node at the head of a linked list.

Linked list is also a very important topic in terms of interviews. Most asked linked list interview questions.

Count number of nodes in a linked list

Program to find middle element of a linked list

Reverse a Linked List using Recursion

Reverse a linked list using iterative approach

Delete a node at Nth Position from Linked List

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , , . Bookmark the permalink.