Page 385 - computer science (868) class 11
P. 385

20        {
                  21           if(i==n)  // not found base case

                  22             return -1;
                  23           else if(arr[i]==v)  // found base case

                  24             return i;
                  25           else

                  26             return linear(i+1,v); // recursive case
                  27        }
                  28

                  29        public static void main(int s,int v)

                  30        {
                  31           LSearch obj = new LSearch(s);
                  32           obj.fillarray();

                  33           int p=obj.linear(0,v);
                  34           if(p==-1)

                  35           System.out.println(v+"not found in array ");
                  36           else

                  37           System.out.println(v+" found in location: " +(p+1));
                  38        }

                  39      }


                 The output of the preceding program is as follows:
















                 Enter 7 elements

                 12 23 34 67 89 90 22
                 89 found in location: 5












                                                                                                                       383
                                                                                                           Recursion   383
   380   381   382   383   384   385   386   387   388   389   390