Question: Write a program that animates the linear search algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a random
Write a program that animates the linear search algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a random order. The array elements are displayed in a histogram, as shown in Figure 22.12. 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 and repaints the histogram with a bar indicating the search position. This button also freezes the text field to prevent its value from being changed. When the algorithm is finished, display the status in the label at the top of the border pane to inform the user. Clicking the Reset button creates a new random array for a new start. This button also makes the text field editable.
The key is found in the array at index 6 The key is not in the array 20 20 19 19 18 18 17 17 16 16 15 14 14 13 12 12 11 11 10 10 8 Key (in double) 8 Key (in double) 4.5 Step Reset Step Reset
Step by Step Solution
3.56 Rating (174 Votes )
There are 3 Steps involved in it
Program Plan Declare a class Exercide22 16 which extends from Application In class Exercise22 16 ove... View full answer
Get step-by-step solutions from verified subject matter experts
