Java Reference
In-Depth Information
157 && buckets[bucket] == null )
158 bucket++;
159 if (bucket < buckets.length)
160 current = buckets[bucket];
161 else
162 throw new
NoSuchElementException();
163 }
164 else // Move to next element in bucket
165 current = current.next;
166 return current.data;
167 }
168
169 public void remove()
170 {
171 if (previous != null &&
previous.next == current)
172 previous.next = current.next;
173 else if (previousBucket < bucket)
174 buckets[bucket] = current.next;
175 else
176 throw new IllegalStateException();
177 current = previous;
178 bucket = previousBucket;
179 }
180
181 private int bucket;
182 private Node current;
183 private int previousBucket;
184 private Node previous;
185 }
186 }
713
714
ch16/hashtable/HashSetDemo.java
1 import java.util.Iterator;
2 import java.util.Set;
3
4 /**
5 This program demonstrates the hash set class.
6 */
7 public class HashSetDemo
Search WWH ::




Custom Search