Monday, February 19, 2007

What Does Acid Reflux Sound Like

Interpolation

package Interpolation;
import java.io. *;

public class InterpolationSearch

{/ / Returns the position of the back element (starting at 0),
/ / if it exists -1 if not.
private static int search (int [] a, int left, int right, int k) {

/ / element is smaller than the first or greater than the last.
if ((k \u0026lt;a [0]) return -1;

/ search / otherwise. Else {



if (a [left] == k) return
left;
else if ((left == right)

if (center to right)
return -1;
if (k \u0026lt;a [mid])
return search (a, right, middle - 1, k);

else return search (a, middle, right, k);}

}}


public static void main (String [] args) throws IOException {

int [] a = {2, 5, 6, 9, 13, 18, 21, 26, 26, 66};
System.out.println ("List");
for (int i = 0; i \u0026lt;a.length; i + +)
System.out.println (a [i] + "") ;
System.out.println ();
System.out.print ("Enter an integer:");
BufferedReader kb = new BufferedReader (new InputStreamReader (System.in));
int k = Integer.parseInt (kb.readLine ());

int s = search (a, 0, a.length - 1, k);
if (s = -1!)
System.out.println ("The element" + k + "is at position:" + s );

else System.out.println ("The element" + k + "does not exist.");

}}

0 comments:

Post a Comment