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

I know this problem seems long, but it is just editing an existing program. I po

ID: 3621082 • Letter: I

Question

I know this problem seems long, but it is just editing an existing program. I posted the three files to the program below that I need to modify, (.cpp file, .h file, and tester file). I will rate the answer as Lifesaver! Any help will be much appreciated!



(a) Develop a new function member called search() to search for a data value in the list. If the function found the data, it should return the index of the element. Note that the first element corresponds to the index 0. If the data value doesn’t exist in the list, your function should return -1. You have to declare the function at the LinkedList.h and provide the implementation at the LinkedList.cpp. Then, invoke the function at the linked_list_tester.cpp to test it. This is the prototype of the function.

int search(ElementType dataVal);


If the function can’t be executed by any reason (For example, index is too big.), it return false. Otherwise, it should return true.

----------------------------------------------------------------------------------------------------------------------------

LinkedList.h

Explanation / Answer

Here is the answer. Let me know if you have any further questions or if you do not understand what I did or how to implement it: ----------------------------------------------------------------------------------------------- In "LinkedList.h", add under "public" (roughly around line 25 right after "display" function): int search(ElementType dataVal); bool swap(int first, int second); ------------------------------------------------------------------------------------------------ In "LinkedList.cpp", add anywhere: int LinkedList::search(ElementType dataVal) { int index = 0; Node * ptr = first; while (ptr != NULL) { if (ptr->data == dataVal) return index; ++index; ptr = ptr->next; } return -1; } bool LinkedList::swap(int first, int second) { Node *ptr = this->first; if (first >= mySize || second >= mySize || first < 0 || second < 0) return false; if (first == second) return true; int firstValue; int secondValue; for (int x=first;x!=0;--x) ptr = ptr->next; firstValue = ptr->data; ptr = this->first; for (int x=second;x!=0;--x) ptr = ptr->next; secondValue = ptr->data; ptr->data = firstValue; ptr = this->first; for (int x=first;x!=0;--x) ptr = ptr->next; ptr->data = secondValue; return true; } --------------------------------------------------------------------------------------------- In "linked_list_tester.cpp", add the following anywhere (toward the end is fine...you can also change this to say what you wish): int index = intList.search(500); cout