Introduction
Create an interactive program to demonstrate a binary search.
Design
- The program will search positive integers
- The program will display the search results (found, not found)
- The program will start with 20 random numbers in sort order
- The program will loop until the user enters the "quit" command
- The program will display information explaining the commands
- The program will accept commands (strings) from the user
- Commands are case insensitive
- The first non-blank characters entered will be the command
- Blank commands (empty strings) are ignored
- Illegal commands will generate an error message
- The commands are
- D - display the numbers
- S - search the numbers for a specified value
- G - generate a new set of random numbers in sort order
- Q - quit the program
- # - change the number of numbers to search (0 to 40)
(a new set of random numbers will be generated
in sort order)
Binary Search Algorithms
Wikipedia - Binary Search
Binary Search – Data Structure and Algorithm Tutorials
Search algorithms/Binary_search
Try This
Use positive and negative integers.
Use floating point numbers.
Search (case insensitive) strings rather than numbers.
Show each step of the search.