Finding last Occurrences of variable in an array using recursion in C++
Given an array and a value K, we have to find the last occurrence of the value K in the array. We will do this by using recursion in C++ and print out the index of the last occurrence.
We are given an array and a variable we have to find the last occurrence of that variable in the array.
We will use recursion for this. We will start the recursion from the start of the array and find the last index where the variable occurs. The base case will be if we traverse through the whole array and can't find the variable we will return -1.
Now we will put a recursive call and we will keep a condition that if my current index is equal to the variable and there is no element equal to the variable after my current index{this we be done when the recursive call returns -1} we will return the current index value.
Project Files
| .. | ||
| This directory is empty. | ||