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

We studied linear search, which searches an array A for an element X by starting

ID: 3625748 • Letter: W

Question

We studied linear search, which searches an array A for an element X by starting at index 0 and proceeding to look in indices 1, 2, 3, ..., Size-1 for X. Write the code for a function int ReverseLinearSearch(int A[], int Size, int X) which searches A for X in reverse order, i.e., starting at Size-1 and working down to 0. The function shall return the index of X or -1 if X is not found.

Explanation / Answer

int search(int A[],int Size,int X) { for(int i=Size-1;i>=0;i--) { if(a[Size]==X) { return Size; }//end of if }//end of for return -1;//will return -1 if not found } ..........//in the main program int res=search(int A[],int Size,int X); if(res==-1) cout
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