do {
comp = 0;//Using integers for the bubble sorting
if(ListDS)//Checking the existence of the head pointer
{
prev = ListDS;
if(prev->next)//Checking the existence of a second element on the list
{
nd = prev->next;
if(prev->surname > nd->surname)//comparison of the first two elements
{
comp++;
temp = prev->next;
prev->next = nd->next;
nd->next = ListDS;
ListDS = temp;
}
elseif(prev->name > nd->name)
{
comp++;
temp = prev->next;
prev->next = nd->next;
nd->next = ListDS;
ListDS = temp;
}
else {}
while(nd->next)//Checking for any next element
{
prev2 = prev;//setting pointers
prev = nd;
nd = nd->next;
if(prev->surname > nd->surname)//comparison of n-th and (n+1)-th elements
{
comp++;
temp = prev->next;
prev->next = nd->next;
nd->next = prev2->next;
prev2->next = temp;
}
elseif(prev->name > nd->name)
{
comp++;
temp = prev->next;
prev->next = nd->next;
nd->next = prev2->next;
prev2->next = temp;
}
else {}
}
}
}
} while (comp); //Checking if comparisons have been executed
I expect any number of elements on the list, thus the checks on the head, as well as the first two elements of the list.
The thing is that the code is running without any errors popping up, although the comparison of the strings just doesn't happen at all. What can I do?