I wrote simple function, that merge two sorted list into one. Unfortunately, I couldn't get a result, I don't know why. Compilator don't show any statements, and stop working while starting the function. It seems me to be ok everything. Check that, please. Below is shown the code.
node list_sort (node*& h, node*& h1, node*& h2)
{
if (h1 && h2 == NULL)
{
h = h1;
return *h;
}
if (h2 && h1 == NULL)
{
h = h2;
return* h;
}
if (h1 == NULL && h2== NULL)
{
h = NULL;
return* h;
}
if (h1 && h2) // condition required to set a head
{
if (h1->vol > h2->vol)
h = h2;
else
h = h1;
}
mode* p;
p = h;
while (h1 && h2)
{
if (h1->vol > h2->vol)
{
p->next = h2;
h2 = h2->next;
}
else
{
p->next = h1;
h1 = h1->next;
}
p = p->next;
}
if (h1)
{
while (h1)
{
p->next = h1;
h1 = h1->next;
p = p->next;
}
}
else
{
while (h2)
{
p->next = h2;
h2 = h2->next;
p = p->next;
}
}
h1 = NULL;
h2 = NULL;
return* h;
}