Tag Archives: linked list

Swap two given nodes in linked list

Swapping given nodes in linked list Problem statement for swapping two nodes in linked list: Given a singly linked list and the data of any two nodes of the linked list, you have to swap the nodes of the linked list without swapping data. Swap nodes of linked list Example: Consider a singly linked list… Read More »

Swap data of adjacent nodes in a linked list

Pairwise swap data of adjacent nodes in a linked list Problem statement for swapping data of adjacent nodes in a linked list: Given a singly linked list, you have to swap the data of adjacent nodes without changing the links between the nodes. Pairwise swap data of adjacent nodes in a linked list Example: Consider a singly linked… Read More »

Rearrange a given linked list

Rearrange list in-place Problem statement to rearrange list: Given a singly linked list, rearrange list in-place, such that, starting from the last node, nodes are alternately placed in the beginning of list. Rearrange list Example: Consider a singly linked: 7-> 3-> 9-> 4-> 2-> 8-> 6-> NULL Resultant linked list should be 7-> 6-> 3->… Read More »

Alternating merge of two linked lists

Alternating merge of two linked lists Problem statement for alternating merge of two linked lists: Given two singly linked lists, you have to merge two linked lists alternatively. Alternating merge of two linked lists Examples: Consider two singly linked lists where List 1 has lesser nodes: 1-> 8-> 3-> 7-> NULL 5-> 3-> 9-> 13->… Read More »

Sort linked list whose alternate nodes are in ascending and descending order

Sort list whose alternate nodes are in ascending and descending order without using sorting techniques Problem statement to sort list whose alternate nodes are in ascending and descending order: Given is a singly linked list whose alternate nodes are sorted in ascending and descending order i.e. nodes at odd positions form an ascending ordered linked list… Read More »

Insertion sort on a singly linked list

Insertion sort list Problem statement for insertion sort list (linked list): Given a singly linked list, you have to apply insertion sort on linked list. Insertion sort list Example: Consider a singly linked list 3-> 7-> 2-> 8-> 1-> 9-> 9-> 5-> 6-> NULL After insertion sort, the resultant list should be 1-> 2-> 3-> 5->… Read More »

Sorted insert in linked list

Sorted insert in linked list Problem statement for sorted insert in linked list: Given a sorted singly linked list, you have to insert nodes into the linked list in sorted order. Sorted insert in linked list Example: Consider a sorted singly linked list 1-> 2-> 6-> 19-> 28-> NULL After inserting, say 10, resultant linked… Read More »

Quicksort a linked list

Quicksort a linked list Problem statement to quicksort list: Given a singly linked list, you have to apply quicksort on the linked list. Quicksort list Example: Consider a singly linked list 23-> 3-> 1-> 9-> 10-> 8-> NULL Resultant list should be 1-> 3-> 8-> 9-> 10-> 23-> NULL Algorithm to quicksort list: Partition Select… Read More »

Remove middle points from linked list of line segments

Removing middle points from linked list of line segments Problem statement to remove middle points of a line represented by a linked list: Given a singly linked list of coordinates in the form of (x,y) that represent points on a horizontal or vertical line, you have to remove all the middle points and represent the… Read More »

Removal of duplicate nodes from unsorted linked list

Removing duplicate nodes from an unsorted linked list Problem statement to remove duplicate nodes from unsorted linked list: Given an unsorted singly linked list, you have to remove duplicate nodes from it. Removing duplicate nodes from an unsorted linked list Example: Consider a singly linked list 3-> 7-> 1-> 9-> 9-> 6-> 7-> 8-> 2->… Read More »