If someone could help me find where i am going wrong, i have been working on this code for a long time but cannot get it right. It takes a linked list to be sorted by passing *head as head pointer. The output of that function should be the same linked list sorted in ascending order such that the header node will be the smallest value in the list.
void sortByCount (struct lnode** head) {
struct lnode* temp= (*head);
struct lnode* temp2 = (*head);
int i;
int j;
int counter = 0;
while(temp != NULL)
{
temp = nodeGetNext(temp);
counter++;
}
for( i = 1; i<counter; i++)
{
temp2=(*head);
bool flag = false;
for(j = 1; j<counter-i+1;j++)
{
if(countCmp(temp2,nodeGetNext(temp2))>0)
{
swap(head,temp2,nodeGetNext(temp2));
}
if(countCmp(temp2,nodeGetNext(temp2))== 0 && (wordCmp(temp2,nodeGetNext(temp2))>0))
{
swap(head,temp2,nodeGetNext(temp2));
flag = true;
//continue;
}
}
temp2 = nodeGetNext(temp2);
}
}