LogicDecode / hactoberfest2023

Pull request best of your code snippets to help open source community
MIT License
10 stars 143 forks source link

Merge Sort for Linked List #78

Closed m-soumik closed 11 months ago

m-soumik commented 11 months ago

Let the head be the first node of the linked list to be sorted and headRef be the pointer to head. Note that we need a reference to head in MergeSort() as the below implementation changes next links to sort the linked lists (not data at the nodes), so the head node has to be changed if the data at the original head is not the smallest value in the linked list.