私は魔法の弾丸型の解決策を持っていません。私は、さまざまな場所であなたのコードにThread.sleep(...)
コールを入れなければならないと思います。
public class BubbleSort {
private long sleepBetweenIterationsMillis;
public BubbleSort(long sleepBetweenIterationsMillis) {
this.sleepBetweenIterationsMillis = sleepBetweenIterationsMillis;
}
...
// iterate through the list bringing the highest value to the top
// wait a certain number of millis
Thread.sleep(sleepBetweenIterationsMillis);
// loop
...
}
これらのスリープコールを入れるソートアルゴリズムのポイントを選ぶことは、「繰り返し」とみなされる点によって異なります。スリープ値を注入する代わりに、代わりに、スリープ値を動的に変更する可能性のあるスリープマネージャを呼び出すか、ユーザー入力に基づいて何かを呼び出すことができます。
public interface SleepManager {
public void sleep();
}
public class BubbleSort {
private SleepManager sleepManager;
public BubbleSort(SleepManager sleepManager) {
this.sleepManager = sleepManager;
}
...
// iterate through the list bringing the highest value to the top
// call the manager which can dynamically slow or speed up the iterations
sleepManager.sleep();
// loop
...
}
MVCの質問にはコメントできません。あなたは、あなたが試したことと達成したいことを中心に、より具体的な別の質問を書く必要があります。
@Gray Done。手伝ってくれますか? – Granttastic