I have made an insertion sort function for a doubly linked list of polynomials , i cant figure out the error , please help me with it!
void insertionSort()
{
node* temp=head;
while(temp->next != NULL)
{
node* second =temp->next;
if (second->exponent==temp->exponent)
{
temp=temp->next;
}
else
{
second->previous->next=second->next;
second->next->previous=second->previous;
if (head->exponent > second->exponent)
{
second->next=head;
second->previous=NULL;
head->previous=second;
head= second;
}
node* current = head->next;
while(current->exponent < second->exponent)
{
current=current->next;
}
second->next=current;
second->previous=current->previous;
current->previous->next=second;
current->previous=second;
}
}
}