forked from w0rthy/ArrayVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwaps.java
More file actions
63 lines (56 loc) · 1.56 KB
/
Swaps.java
File metadata and controls
63 lines (56 loc) · 1.56 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package array.visualizer;
import static array.visualizer.ArrayVisualizer.*;
/**
*
* @author S630690
*/
public class Swaps {
public static void swap(int[] a, int i, int j) {
marked.set(1, i);
marked.set(2, j);
aa+=2;
//if(Math.random()*8<1.0)
//sleep(1);
// TODO Auto-generated method stub
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void swap(int[] a, int i, int j, int pause) {
marked.set(1, i);
marked.set(2, j);
aa+=2;
sleep(pause);
// TODO Auto-generated method stub
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void swapnm(int[] a, int i, int j, int pause) {
sleep(pause);
aa+=2;
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void swapUpTo(int pos, int to){
if(to - pos > 0)
for(int i = pos; i < to; i++)
swap(array, i, i+1, i%240/239);
else
for(int i = pos; i > to; i--)
swap(array, i, i-1, i%240/239);
}
public static void swapUpToNM(int pos, int to){
if(to - pos > 0)
for(int i = pos; i < to; i++)
swapnm(array, i, i+1, i%240/239);
else
for(int i = pos; i > to; i--)
swapnm(array, i, i-1, i%240/239);
}
public static void swapUp(int pos) {
for(int i = pos; i < array.length; i++)
swap(array, i, i+1,i%180/179);
}
}