Program to Delete a Linked List

Write a program to delete a linked list. Given a linked list, we have to write a code to delete a linked list.

To delete a complete linked list, traverse all the nodes of a linked list and delete one by one.

Print Middle Element of a Linked List

How to Delete a Linked List

To delete a node one by one maintain two pointers.  The first pointer points to head and the second pointer keeps the reference to next node. So when a node is free, you can assign the reference of next node using the second pointer.

C Program to Reverse a Linked List using Recursion

Write a c program to reverse a linked list using recursion. Given a singly linked list, we have to write a code to reverse a linked list using recursion. This question is very important in terms of interviews.

In my previous post, I have explained C program to reverse a singly linked list. In this post, We are going to write a code to reverse a linked list using recursion.  If you are not familiar with the concept of recursion then check my previous tutorial on recursion vs iteration.

The time complexity to reverse a linked list using recursion is O(n). 

C Program to Count Number of Nodes in a Linked List

Write a c program to count number of nodes in a linked list. In this tutorial, We are going to write a c code to count the number of nodes in a linked list.

What is Linked List?

A linked list is a collection of nodes, each pointing to next node by means of a pointer. In linked list, each node consists of two parts, a data and a pointer to next node (address of next node).

In linked list, elements are not stored at contiguous memory locations.

You can check this video tutorial on linked list in which i have explained what is linked list? Array vs linked list.

C Program to Count Number of Nodes in a Linked List

C Program to Count Number of Nodes in a Linked List