ProAnswers.org

How to split a linked list given a pivot value

How to split a linked list given a pivot value

We need to maintain a pointer HEAD1 which will point to the starting of the right half of the list formed after splitting.

node *HEAD1;
HEAD1 = pivot_node->next;
pivot_node -> next = NULL;

/* pivot_node is the node which has the pivot value /
/
head and HEAD1 will point to the starting of the two new lists formed after splitting /
/
head is the pointer to the starting of the list given to us i.e the list before splitting */