example.bubbleSortVisualization.BubbleSort   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 10
eloc 9
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A BubbleSort(DrawingPanel) 0 2 1
A sort() 0 7 4
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