-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertionSort.js
More file actions
47 lines (40 loc) · 923 Bytes
/
insertionSort.js
File metadata and controls
47 lines (40 loc) · 923 Bytes
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
42
43
44
45
46
function setup(){
iSortCanvas = createCanvas(1000, 800);
iSortCanvas.parent("iCanvas");
for (var i = 0; i<width; i++){
iLines[i] = random(0, height);
}
n = 0;
j = 0;
}
function draw(){
background(0);
for (var i = 0; i<iLines.length; i++){
if (i%2==0){
stroke(155);
strokeWeight(5);
line(i, height, i, height-iLines[i]);
}else{
stroke(55);
strokeWeight(5);
line(i, height, i, height-iLines[i]);
}
}
if (n<iLines.length){
var curr = iLines[n];
j = n-1;
while (j>=0){
if (curr<iLines[j]){
iLines[j+1] = iLines[j];
iLines[j] = curr;
j-=1
}else{
break;
}
}
n+=1;
}else{
console.log(iLines);
noLoop();
}
}