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

Hi, Please help me out.. I\'m studying for my finals and need help in writing th

ID: 3659375 • Letter: H

Question

Hi, Please help me out.. I'm studying for my finals and need help in writing the following code in C++: Please write a function called *** int lastIndexOf(ListType list, int val) **** which takes in a list and : returns index of last occurrence of val in the list; returns -1 if val appears nowhere in the list. Count indices starting from 0, as we do with arrays. For Example: Example1: list = (3 7 5), val = 7 return 1 since index of 7 is 1 assuming we start from 0 Example2: list = (3 7 5 7), val = 7 returns 3 Example3: list = (3 4 5), val = 8 return -1 Example4: list = (3 9 5 4 9 2 9 9 4 5), val = 9 returns 7 Example5: list = (), val = 8 returns -1

Explanation / Answer

int lastIndexOf(ListType list, int val){ ListType *temp ; int index = -1; int lastOccourrence; temp = head; for(int i=0;temp->next!=null;i++){ if (temp->data = val) index = i; i++; } temp = temp ->next; } return index; }

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