Hi there all,
I have to implement a recursive sequential that searches for an element in an UNSORTED array and displays the position of that element. This is my code so far.
If there is no matching elements we are supposed to return a -1. Would someone please help me with this? Thank you.Code://'listSize' is a parameter that inputs size of the array into function //'item' is a parameter that inputs the current value of the function //list is the array itself and therefore is also a pointer //returns the position of the array that we are searching for int sequentialSearch(int item, int* list, int listSize){ if (listSize == 0){ return -1; } if (*list == item){//if first element is equal to listSize return 0; } else sequentialSearch(int item, int* list, int listSize){ list = list + 1; } }



LinkBack URL
About LinkBacks


