Complete the following function definition to recursively print the index of a unique value in an array or -1 if the value is not found:

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

Complete the following function definition to recursively print the index of a unique value in an array or -1 if the value is not found:

1   int getIndex(int *a, int s, int v) {
2       if(       ) { // if no values are found
3  
4       }
5      if(a[s-1] == v) { // if a value is found
6          
7       }
8       return getIndex(          ); // recurse to check next value
9   }

Hint:
Recurse through the array by counting down from size.

1. Complete the one line of code for line 2:
2. Write one line of code for line 3:
3. Write one line of code for line 6:
4. Complete the one line of code for line 8:

 

please send an atom code. not other software

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr