-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeySort.java
More file actions
51 lines (44 loc) · 1.23 KB
/
KeySort.java
File metadata and controls
51 lines (44 loc) · 1.23 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
public class ksort {
public String alphabet = "abcdefgh";
public String[] items;
public ksort(){
int size = (int)'h' + 2*(int)'9';
items = new String[size];
}
public boolean add(String s){
if (isSuitable(s)){
items[(int)s.charAt(0) +(int)s.charAt(1)+(int)s.charAt(2) - 1] = s;
return true;
}else {
return false;
}
}
public int index(String s) {
if (isSuitable(s)){
return (int)s.charAt(0) +(int)s.charAt(1)+(int)s.charAt(2);
}else {
return -1;
}
}
public boolean isSuitable(String item) {
boolean contains = false;
if (item.length() == 3) {
for (int i = 0; i < alphabet.length(); i++) {
if (alphabet.charAt(i) == item.charAt(0)) {
contains = true;
i = alphabet.length();
}
}
if(contains && (def(item.charAt(1)) && def(item.charAt(2)))){
return true;
}else{
return false;
}
} else {
return false;
}
}
public boolean def(char c){
return (int) c >= 48 && (int) c <= 57;
}
}