All of the functions to implement the mergesort algorithm are implemented in the split, merge and mergesort agents in the DL_CELL class. We can utilize this capability with a call to the mergesort agent for the DL_CELL object pointer head.
// ************************************ //
// merge sort for CHAR_DLLIST //
// ************************************ //
void CHAR_DLLIST::mergesort()
{
head = head->mergesort(head);
//must reset end
if(head==NULL) exit(-1);
else{
CHAR_DL_CELL *again,*before;
again = head->next;
while(!(again==NULL)){
before = again;
again = again->next;
}
end = before;
end->next = NULL;
}
}