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.

Reverse a linked list using iteration.

Subscribe Our Tutorials

Get Latest Updates on Facebook

Reverse a linked list using Recursion.

C Program to Delete a Linked List

We have discussed the logic of  a program, let’s implement it.

Output

Time Complexity : O(n)

Space Complexity : O(1)

WebRewrite

About WebRewrite

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

    To delete a linked list we need a pointer to the head node of linked list. We will write a function “deleteLinkedList” which takes head node of a linked list as input and deletes all nodes of given linked list one by one from head till tail node.