swapping nodes in a singly linked list

I am trying to write a program that gets the input from a word file puts the word in a node and puts the frequency in the node as well. I got that working but now I am trying to sort the list from in descending order of frequency and I feel like I am spinning in circles. I will post code but I warn you its a mess

void wordCloud::freqSort()
{
wordNode* largest;
wordNode* search;
wordNode* partSorted;
wordNode* temp;

partSorted = head;

while(partSorted != NULL)
{
search = partSorted;
largest = partSorted;

while(search->next != NULL)
{
if(search->next -> freq_count > largest -> freq_count)
{
temp = search;
largest = search->next;
}
if(search->next != NULL)
search = search->next;
}

if(head->myWord == largest->myWord)
{
/*properlyHandleHeadFirst(largest, search, partSorted);*/
/*printWordCloud();*/
}
else
{
properlyHandleRestofList(largest, search, partSorted, temp);
/*printWordCloud();*/
}


partSorted = partSorted->next;
}

}

//void wordCloud::properlyHandleHeadFirst(wordNode* large, wordNode* search, wordNode* partSorted)
//{
//if(head == large);
//else
//{
// head = large;
// search->next = NULL;
//}
//}

void wordCloud::properlyHandleRestofList(wordNode* large, wordNode* search, wordNode* partSorted, wordNode* temp)
{
wordNode* temp2;
wordNode* temp3;
temp3 = partSorted->next;
temp2 = large->next;
partSorted = large;
large->next=temp3;
partSorted->next->next = temp2;
temp=temp2;
search->next = NULL;


}

string wordCloud::lowerCase(string text)
{
for(int i = 0; text[i]; i++)
text[i] = tolower(text[i]);

return(text);
Topic archived. No new replies allowed.