BinarySearch - /*Binary Search PseudoCode 1. if the code...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/*Binary Search PseudoCode 1. if the code does not have a high or low inputs create these variables low = 0 and high = array.length-1 2. then do a while loop While (low<= high) 3. Create a new variable called mid which = (high+low)/2 4. if the mid is equal to the key (element you are searching for) return mid 5. else if the key is less than mid high= mid-1 6. else low= mid+1 7. come out of the while loop and return -1 if nothing is found */ /*public int binearSearch (int[] array, int key) { int low = 0, high= array.length-1; while (low<=high) { int mid = (low + high)/2; if (array[mid] == key) { return mid; } else if (key<array[mid]) { high = mid-1; } else { low = mid+1; } return -1; }*/ public class BinarySearch { // the main method public static void main(String[] args) { // create the integer array first int[] numbers = {-5, -10, 30, 1, 5, 100, 15, 25, 0, 10}; // display the values System.out.println("----------------------"); System.out.println("Array before sorting: "); displayArray(numbers); // calls the display method
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/06/2010 for the course CSE CIS3023 taught by Professor Seema during the Spring '10 term at Florida College.

Page1 / 3

BinarySearch - /*Binary Search PseudoCode 1. if the code...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online