Question: Instead of using a thread and a pause method, use the Timer class introduced in Section 10.9 to ani mate an algorithm. Whenever the timer

Instead of using a thread and a pause method, use the Timer class introduced in Section 10.9 to ani mate an algorithm. Whenever the timer sends out an action event, run the algorithm to the next step and display the state. That requires a more extensive recoding of the algorithm. You need to implement a runToNextStep method that is capable of running the algorithm one step at a time. Add sufficient instance variables to the algorithm to remember where the last step left off. For example, in the case of the selection sort algorithm, if you know the values of alreadySorted and markedPosition, you can determine the next step.

Step by Step Solution

3.57 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on your question it seems like youre asking for help on how to use the Timer class to animate an algorithm taking it step by step Lets use the selection sort algorithm as an example Firstly we n... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!