a guest May 22nd, 2019 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1. main class ( “Demo-Driver” )
  2. a.   Create a Java file of “public class RandomAccessBinaryFileRecursiveBinarySearch”
  3. class containing the main method.
  4. b.   It will create a Scanner object to receive a value into “nextShort()”  from the user to
  5. search the file for.
  6. c.   It will create a “File” object for “BinFileShort”.
  7. d.   It will create a “RandomAccessFile” object to read the file data.
  8. e.   Create “BinaryRecursiveSearch” object to call the recursive binary search method.
  9. f.    In a loop, get a short to search for. You can use a “Y” or “N” algorithm to test for end of
  10. program as the binary search program did. I quickly tired of typing the “Y” and looped
  11. until a sentinel value was read.
  12. g.   Invoke the binary search:
  13.                 long result = fileArray.binarySearch( randomAccessFile, 0, 4999,
  14.                                                                             searchValue, callNumber);
  15.                 The “callNumber” allows to determine how many recursions it took. It is optional.
  16. h.   Display whether or not the value was found.
  17.       Enter a value to search for: 7398
  18.       Call binarySearch. Times called 1
  19.       7398 was found at element 2499
  20. 2.  Library class “BinaryRecursiveSearch”
  21. a.   Create a Java file of “public class BinaryRecursiveSearch” class containing the “binarySearch”
  22. method.
  23. b.   Check to see if the value searched for was not found. If so, return the long “-1.”
  24. c.   Calculate the middle position of the area being searched.
  25. d.   Resolve the byte-short alignment: “long positionValueForShort = 2 * positionValue;” .
  26. e.   Seek that position.
  27. f.    Read the short at that position: readShort().
  28. g.   Recursively call the left half or right half of “binarySearch()” .
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand