-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.java
More file actions
39 lines (30 loc) · 1.03 KB
/
Util.java
File metadata and controls
39 lines (30 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
package DataStructures;
import java.util.List;
/**
* @author Guyue Zhou (SouICry) gzhou.email@gmail.com
* @since 12/22/2015
*/
public class Util {
public static void swap(Comparable[] elements, int aIndex, int bIndex){
Comparable temp = elements[aIndex];
elements[aIndex] = elements[bIndex];
elements[bIndex] = temp;
}
public static void printArray(Object[] arr){
StringBuilder s = new StringBuilder(arr.getClass().getName()).append("[").append(arr.length).append("] { ");
for (int i = 0; i < arr.length - 1; i++){
s.append(arr[i].toString()).append(", ");
}
s.append(arr[arr.length - 1].toString()).append(" }");
System.out.println(s);
}
@SuppressWarnings("unchecked")
public static boolean isSorted(Comparable[] arr){
for (int i = 0; i < arr.length - 1; i++){
if (arr[i].compareTo(arr[i + 1]) > 0){
return false;
}
}
return true;
}
}