Question: C programming - These last three functions implement the mergesort algorithm. Mergesort works by splitting the list into two halves, sorting each half recursively, and
C programming - These last three functions implement the mergesort algorithm. Mergesort works by splitting the list into two halves, sorting each half recursively, and then merging the sorted halves.
typedef int (*compare_fn)(Object* obj1, Object* obj2);
typedef struct LinkedListNode_s { Object* obj; struct LinkedListNode_s* next; } LinkedListNode;
// // Mergesort //
// Assuming list1 and list2 are sorted lists, merge list2 into list1 while keeping it sorted // The sort order is determined by the compare function void merge(LinkedListNode** list1_head, LinkedListNode** list2_head, compare_fn compare) { // IMPLEMENT THIS }
// Split the list head in half and place half in the split list // For example, if head has 8 nodes, then split will move 4 of them to split_head void split(LinkedListNode** head, LinkedListNode** split_head) { // IMPLEMENT THIS }
// Implement the mergesort algorithm to sort the list // The sort order is determined by the compare function void mergesort(LinkedListNode** head, compare_fn compare) { // IMPLEMENT THIS }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
