| Total Complexity | 5 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package example.bubbleSortVisualization; |
||
| 6 | public class BubbleSort extends VisualSort { |
||
| 7 | /** |
||
| 8 | * Construct BubbleSort using default parameters |
||
| 9 | * |
||
| 10 | * @param drawingPanel The DrawingPanel on which to display the sort |
||
| 11 | */ |
||
| 12 | public BubbleSort(DrawingPanel drawingPanel) { |
||
| 13 | super(1000, drawingPanel); |
||
| 14 | } |
||
| 15 | |||
| 16 | /** |
||
| 17 | * A lazy implementation of the Bubble Sort algorithm |
||
| 18 | */ |
||
| 19 | protected void sort() { |
||
| 20 | for (int pass = 0; pass < list.length; pass++) { |
||
| 21 | for (finger = 0; finger < list.length - 1; finger++) { |
||
| 22 | if (list[finger] > list[finger + 1]) { |
||
| 23 | swap(finger, finger + 1); |
||
| 24 | } |
||
| 25 | sleep(2); // ideally this delay is a multiple of the animation frame delay |
||
| 26 | } |
||
| 30 |