title: Recursive C Program Linearly Search Element Given Array
signature: func recursiveCProgramLinearlySearchElementGivenArray(arr []int, l int, r int, x int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, l int, r int, x int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, l, r, x),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{10, 74, 5}, 
  	0, 
  	2, 
  	1, -1)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{-90, 72, 36, 96, 42, 0, -66, 5}, 
  	0, 
  	7, 
  	96, 3)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 5}, 
  	0, 
  	1, 
  	-1, -1)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{99, 70, 67, 5}, 
  	0, 
  	3, 
  	3, -1)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-98, -98, -26, -26, -24, -18, -16, 80, 5}, 
  	0, 
  	8, 
  	80, 7)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{1, 1, 1, 1, 0, 1, 5}, 
  	0, 
  	6, 
  	1, 0)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{1, 5, 12, 12, 17, 17, 12, 95, 96, 98, 5}, 
  	0, 
  	0, 
  	12, -1)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{50, -70, -30, -54, 6, -10, 70, 84, 5}, 
  	0, 
  	8, 
  	27, -1)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{0, 1, 5}, 
  	0, 
  	2, 
  	14, -1)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{59, 21, 28, 3, 14, 5}, 
  	0, 
  	5, 
  	28, 2)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def recursive_c_program_linearly_search_element_given_array(arr, l, r, x):
      if (r < l):
          return (- 1)
      if (arr[l] == x):
          return l
      if (arr[r] == x):
          return r
      return recursive_c_program_linearly_search_element_given_array(arr, (l + 1), (r - 1), x)
source_cpp: int recursive_c_program_linearly_search_element_given_array(vector<int> arr, int l, int r, int x) {
    if ( r < l ) return - 1;
    if ( arr [ l ] == x ) return l;
    if ( arr [ r ] == x ) return r;
    return recursive_c_program_linearly_search_element_given_array ( arr, l + 1, r - 1, x );
  }