forked from w0rthy/ArrayVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertionSort.java
More file actions
41 lines (38 loc) · 1.03 KB
/
InsertionSort.java
File metadata and controls
41 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package array.visualizer;
import static array.visualizer.ArrayVisualizer.*;
import static array.visualizer.Swaps.*;
/**
*
* @author S630690
*/
public class InsertionSort {
public static void insertionSort() {
int pos;
for(int i = 1; i < array.length; i++){
pos = i;
//marked.set(0, i);
while(pos>0&&array[pos]<=array[pos-1]){
comps+=2;
swap(array, pos, pos-1,Math.max(pos%50-48,0));
pos--;
}
}
}
public static void insertionSort(int start, int end, double slpamt) {
int pos;
for(int i = start; i < end; i++){
pos = i;
//marked.set(0, i);
while(pos>start&&array[pos]<=array[pos-1]){
comps+=2;
swap(array, pos, pos-1);
sleep(slpamt);
pos--;
}
}
}
}