#include #include using namespace std; struct sortedListNode char letter int occ
ID: 674437 • Letter: #
Question
#include #include using namespace std; struct sortedListNode char letter int occurrences sortedListNode *next; sortedListNode* fromString(string word) sortedListNode *head NULL; for(int i 0; iletter = word [i] newNode->occurrences- 1; newNode->next NULL; if(head NULL) head- newNode else sortedListNode current-head; sortedListNode *prev NULL; while(current != NULL && current etter letter) prev current; current = current->next; if(current != NULL && current etter-new:Node->letter) current->occurrences current occurrences1;
Explanation / Answer
Some changes required inside the function definition of
sortedListNode* operator+(sortedListNode &list1, sortedListNode &list2)
(1).
instead of :
use this :
Although this does not have a significant impact, yet it will help
(2).
Remove
inside
and
because you have already declared it once above the function. And the program is not using the local copy of
structure element anywhere.
(3).
Make the if(temp1 != NULL) and if(temp2 != NULL) parts like below :-
*bold-italicised part below is the new code
if(temp1 != NULL)
{
while(temp1 != NULL)
{
if() {}
else{}
temp1 = temp1->next;
}
}
and
if(temp2 != NULL)
{
while(temp2 != NULL)
{
if() {}
else{}
temp2 = temp2->next;
}
}
The program should work correctly after this. Let me know if you still face any problem
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.