Tag Archives: Singly Linked List

C program to swap two nodes in a linked list

How to swap two nodes in a linked list is a popular problem in data structure. In this post I will explain how to swap two nodes in a linked list. I will explain to swap two nodes without swapping data in a linked list.

Write a C program to create a linked list and accept two node position from user. The program should swap two nodes in linked list without swapping their data.

Continue reading C program to swap two nodes in a linked list

C program to search an element in linked list

Search is one of the most common operation on performed any data structure. In this post I will explain how to search an element in linked list (iterative and recursive) using C program. I will explain both ways to search, how to search an element in linked list using loop and recursion.

Write a C program to create a function to search an element in linked list. If element exists in the linked list then, it should return its index otherwise -1.

Continue reading C program to search an element in linked list

C program to delete all nodes by key in a linked list

Write a C program to create a linked list and delete all nodes by key. How to delete element by key of a linked list in C program. In previous few programs, I explained how to delete first, last or nth element from a singly linked list. In this post I will explain how to delete all nodes by key in a linked list, delete first node by key or delete last node by key in C program.

Continue reading C program to delete all nodes by key in a linked list

C program to delete middle node of Singly Linked List

Write a C program to create a singly linked list of n nodes and delete node from the middle of the linked list. How to delete node from the middle of the singly linked list in C. Algorithm to delete middle node from singly linked list. Steps to delete middle node from singly linked list.

Singly linked list

Continue reading C program to delete middle node of Singly Linked List

C program to delete first node of Singly Linked List

Write a C program to create a singly linked list of n nodes and delete the first node or beginning node of the linked list. How to delete first node or beginning node from the singly linked list in C. Algorithm to delete first node from singly linked list. Steps to delete first node from singly linked list.

Singly linked list

Continue reading C program to delete first node of Singly Linked List

C program to insert node at the middle of Singly Linked List

Write a C program to create a singly linked list of n nodes and insert a new node at the middle of the linked list at nth position. How to insert new node at the middle of a singly linked list in C. Algorithm to insert a new node in middle of a singly linked list. Steps to insert new node at any position in singly linked list.

Singly linked list

Continue reading C program to insert node at the middle of Singly Linked List