4. (Printing a single linked list backward) Include the reversePrint and recursi
ID: 3745808 • Letter: 4
Question
4. (Printing a single linked list backward) Include the reversePrint and recursiveRev in the class linkedListType. Also, write a program (single) linked list backward. (Use either the class unordere the class orderedLinkedList to test your function.) ersePrint, as discussed in this cha dLinkedList o 5. Dividing a linked list into two sublists of almost equa a. Add the opera ion divideMid to the class linkedListType as follows: void divideMid (linkedListType ssublist) //This operation divides the given list //of (almost) equal sizes into two sublists /Postcondition: first points to the first node and last points to the last node of the first sublist sublist.first points to the first node and sublist.last points to the last node of the second sublist. Consider the following statements: unorderedLinkedListExplanation / Answer
I am assuming you are asking for Q.5 as this is highlighted. below is your divideMid function
template<class Type>
void linkedListType<Type>::divideMid(linkedListType<Type> &sublist)
{
nodeType<Type> *current;
nodeType<Type> *mid;
if (first == NULL)
{
sublist.first = NULL;
sublist.last = NULL;
sublist.count = 0;
}
else
if (first->link == NULL)
{
sublist.first = NULL;
sublist.last = NULL;
sublist.count = 0;
}
else
{
mid = first;
current = first->link;
if (current != NULL)
current = current->link;
int i = 1;
while (current != NULL)
{
mid = mid->link;
current = current->link;
i++;
if (current != NULL)
current = current->link;
}
sublist.first = mid->link;
sublist.last = last;
last = mid;
last->link = NULL;
sublist.count = count - i;
count = i;
}
}
Here is Q.4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.