Question: Write a program that animates the binary search algorithm. Create an array with numbers from 1 to 20 in this order. The array elements are
Write a program that animates the binary search algorithm. Create an array with numbers from 1 to 20 in this order. The array elements are displayed in a histogram, as shown in Figure 22.13. You need to enter a search key in the text field. Clicking the Step button causes the program to perform one comparison in the algorithm. Use a light-gray color to paint the bars for the numbers in the current search range and use a black color to paint the a bar indicating the middle number in the search range. The Step button also freezes the text field to prevent its value from being changed. When the algorithm is finished, display the status in a label at the top of a border pane. Clicking the Reset button enables a new search to start. This button also makes the text field editable.
The key is found in the array at index 4 20 19 20 19 10 11 12 13 14 15 16 17 18 18 17 16 10 11 12 13 14 15 Key (in double) 5 Step Reset Key (in double) 5 Step Reset
Step by Step Solution
3.33 Rating (159 Votes )
There are 3 Steps involved in it
Program Plan Declare a class Exercide2218 which extends from Application In class Exercise22 18 over... View full answer
Get step-by-step solutions from verified subject matter experts
