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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started