BubbleSort(DrawingPanel)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
package example.bubbleSortVisualization;
2
3
import org.gannacademy.cdf.graphics.curriculum.VisualSort;
4
import org.gannacademy.cdf.graphics.ui.DrawingPanel;
5
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
            }
27
        }
28
    }
29
}
30