From d4eac2fdcdfefa70e5a3a0e5eaa71a64fb5193d8 Mon Sep 17 00:00:00 2001 From: damianzhenxiaozhi <8603583+damianzhenxiaozhi@users.noreply.github.com> Date: Fri, 27 Sep 2019 18:31:22 +0800 Subject: [PATCH] removing all e in bucket, "use" should decrease MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除槽中所有元素后,hash表占用变量use需要减1。 --- java/18_hashtable/HashTable.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/18_hashtable/HashTable.java b/java/18_hashtable/HashTable.java index 9db7c7f..c2df579 100644 --- a/java/18_hashtable/HashTable.java +++ b/java/18_hashtable/HashTable.java @@ -142,12 +142,14 @@ public class HashTable { } Entry pre; + Entry headNode = table[index]; do { pre = e; e = e.next; if (key == e.key) { pre.next = e.next; size--; + if (headNode.next == null) use--; return; } } while (e.next != null);