Menu

Linked List Node Containing Word Letter Count Word Many Times Word Used Sorted Letter Coun Q43907538

So I have a linked list with each node containing a word, lettercount of the word, and how many times that word has been used. Isorted it by letter count on insertion already, but now I need tosort it by times used within each individual letter count sectionand I am having trouble. I got it to traverse to the part of thelist that needs to be sorted, but I have no clue how to actuallysort 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;
}
}

Expert Answer


Answer to So I have a linked list with each node containing a word, letter count of the word, and how many times that word has bee…

OR