We have the following piece of a C program.I want to understand what this part of code does and its complexity.
void sortLike (node* p)
node* q;
node* min;
node *head = (struct node*) malloc (sizeof (struct node));
head->next = L;
p = head;
// We have to sort the list,obviously.We have the variable p and q which are pointer to node variables.We have determined the size of the head node.I dont understand what node* min and head->next = L; means.
while (p->next->next!=NULL)
{
min = p;
q = p->next;
while (q->next!=NULL)
{
if (min->next->like < q->next->like)
min = q;
q = q->next;
What does this block of code do?
}
node* a = p->next;
p->next = min->next;
min->next = a;
node* b = a->next;
a->next = p->next->next;
p->next->next = b;
p = p->next;
}
L = head->next;
}
What about this one?
Question : What kind of sorting algorithm is this? I would guess it's selection sort.Whats its complexity?Can we turn this into a merge sort algorithm?