Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

All functions should belong to a template class Functions code should be efficie

ID: 3554175 • Letter: A

Question

All functions should belong to a template class

Functions code should be efficient as well as correct.

Class identifier: node, info,next,back,head.

For regular lists, the head points to the first node and it is the only pointer in the list.

For circluar lists-doubly or singly- the head points to last element.

Do not assume the list has nodes and do not assume a client called serchItem before deleting, ifFull before inserting, isEmpty before dleting.......

6)Write a function, to be included in a sorted doubly linked list class, called printBoth, that will first print the list from smallest to largest, and then print it from largest to smallest.


-------------Rewrite all the function above using a circular sorted doubly linked list calss------------



Explanation / Answer

template<class T>

void sorted_doubly_linked_list<T>::printBoth()

{

if(isEmpty()) cout<<"Empty list"<<endl;

else

{

node<T>* temp = head;

/*---Increasing order-----*/

while(1)

{

cout<<temp->info<<" ";

if(temp->next == NULL) break;

else temp = temp->next;

}

cout<<endl<<endl;

/*---Decreasing order-----*/

while(1)

{

cout<<temp->info<<" ";

if(temp == head) break;

temp = temp->back;

}

}

}



template<class T>

void sorted_circular_doubly_linked_list<T>::printBoth()

{

if(isEmpty()) cout<<"Empty list"<<endl;

else

{

node<T>* temp = head->next; //making temp to point to first element

/*---Increasing order-----*/

while(1)

{

cout<<temp->info<<" ";

if(temp == head) break;

else temp = temp->next;

}

cout<<endl<<endl;

/*---Decreasing order-----*/

while(1)

{

cout<<temp->info<<" ";

if(temp == head->next) break;

temp = temp->back;

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote