-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBucket.java
More file actions
32 lines (29 loc) · 1.05 KB
/
Bucket.java
File metadata and controls
32 lines (29 loc) · 1.05 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
/*This code was copied from user drewmore on StackOverflow,
* with some slight alterations to the base. If you would like to find the original code,
* you can find it at
* https://codereview.stackexchange.com/questions/48908/java-implementation-of-spell-checking-algorithm
*/
public class Bucket {
@SuppressWarnings("rawtypes")
public Node first;
@SuppressWarnings("rawtypes")
public boolean get(String in) { //return key true if key exists
Node next = first;
while (next != null) {
if (next.data.equals(in)) {
return true;
}
next = next.getNextNode();
}
return false;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void put(String key) {
for (Node curr = first; curr != null; curr = curr.getNextNode()) {
if (key.equals(curr.data)) {
return; //search hit: return
}
}
first = new Node(key, first); //search miss: add new node
}
}