Question: So I have a linked list with each node containing a word, letter count of the word, and how many times that word has been

So I have a linked list with each node containing a word, letter count of the word, and how many times that word has been used. I sorted it by letter count on insertion already, but now I need to sort it by times used within each individual letter count section and I am having trouble. I got it to traverse to the part of the list that needs to be sorted, but I have no clue how to actually sort this subsection

here is the relevant code to it:

class Node{ public: string word; Node* next; short int letterCount; short int timesUsed=1; };

class LinkedList{ public: Node* head; LinkedList(); void insert(string word); void sort(); string search(int lettersUsed, int timesUsed); void printList(); };

void LinkedList:: sort(){ Node *temp=head; bool wentin; while (temp->next!=NULL) { wentin=false; while (temp->letterCount==temp->next->letterCount) { //sort by times used here temp=temp->next; if (temp->next==NULL) { wentin=true; break; } } if (wentin==true) { break; } temp=temp->next; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!