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

write a search function that takes a string as its argument. It will return the

ID: 3586350 • Letter: W

Question

write a search function that takes a string as its argument. It will return the address of the node holding the string, or Null if the pointer runs off the end of the list. this part of the code has to include:

if(cursor->data == target) return cursor;

Then write a move_front_to_back function. use an extra pointer to hold the first node in the list, then move the head to the second node of the list, and then with still another pointer find the last node in the list and hook the node that used to be at the front to the back.

Main:

Header:

#include #include #include "list!"h" using names pace std; int main() Lilist L1, L2; string target; L1. add( "Charlie" ) ; L1.add("Lisa") L1.add("Drew") L1.add("Derrick"); L1 . add ( "AJ " ) ; L1, add ( "Bojian") ; cout

Explanation / Answer

Node* Lilist::search(std::string item)
{
for(Node* temp = head; temp != NULL; temp = temp->link)//traversing the whole list
{
if(temp->data == item)//checking for the correct match
{
return temp;
}
}
return Null;
}

void Lilist::move_front_to_back()
{
Node* tempHead = head;//store head
for(Node* temp = head; temp->link != NULL; temp = temp->link);//traverse till the last node
temp->link = tempHead;//linking head to the end of the list
head = head->next;//making the 2nd node as head
tempHead->link = NULL;//pointing the last node(i.e previous head) to null, since t

}