Skip to content

Instantly share code, notes, and snippets.

@arjunsk
Last active August 19, 2018 18:38
Show Gist options
  • Save arjunsk/adf470cfbd4ab543af5b9bd6e7ac2d51 to your computer and use it in GitHub Desktop.
Save arjunsk/adf470cfbd4ab543af5b9bd6e7ac2d51 to your computer and use it in GitHub Desktop.
package main;
import noun.BinarySearch;
public class StrategyDriver {
public static void main(String args[]){
BinarySearch bs = new BinarySearch();
/*
* It dynamically selects behavior, based on the array size
*/
int arr[] = {5,2,3,2,5};
bs.setArray(arr);
System.out.println("Value found at index " + bs.search(3) + " from the begin of the sorted array.\n");
int arr2[] = {88, 79, 46, 69, 93, 84, 56, 64, 67, 41, 77, 75, 48, 66, 8, 4, 57,
4, 41, 7, 84, 56, 68, 48, 42, 60, 94, 30, 59, 66, 5, 89, 78, 62,
99, 66, 31, 34, 0, 59, 10, 11, 54, 5, 59, 18, 2, 42, 31, 24, 57,
20, 50, 3, 21, 23, 15, 18, 58, 29, 50, 91, 65, 83, 4, 45, 25, 94,
27, 6, 19, 10, 51, 74, 32, 66, 0, 47, 32, 62, 33, 4, 54, 13, 5,
54, 56, 16, 95, 53, 9, 78, 7, 70, 55, 88, 93, 54, 99, 58, 90 };
bs.setArray(arr2);
System.out.println("Value found at index " + bs.search(4) +" from the begin of the sorted array.\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment