i need help with merge sort.
struct List_A
{
int data;
struct List_A *next;
};
struct List_A *head;
void merge_sort(struct List_A *);
int main(void)
{
....lets say i have a list build --- (list_A = 4,3,2,5)
merge_sort(List_A);
}
void merge_sort(struct List_A *head)
{
struct List_A *cur_one;
struct List_A *cur_two;
if(head == NULL || head->next == NULL)
{
printf("emptyy list");
}
else
{
cur_one = head;
cur_two = head->next;
while((cur_two != NULL) && (cur_two->next != NULL))
{
head = head->next;
cur_two = cur_two->next;
}
cur_two = head->next;
head->next = NULL;
return merge(merge_sort(cur_one),merge_sort(cur_two));
}
}
struct List_A *merge (struct list_A *cur_one, struct List_A *cur_two)
{
struct List_A *cur_three;
if(cur_one == NULL)
{
return cur_two;
}
if(cur_two == NULL)
{
return cur_one;
}
if(cur_one->next < cur_two->age)
{
cur_three = cur_two;
cur_three->next = merge(cur_one->next, cur_two);
}
else
{
cur_three = cur_two;
cur_three->next = merge(cur_one,cur_two->next);
}
return cur_three;
}