先决条件–哈希介绍,使用单链接列表的哈希表,并使用Java的单独链接实现我们自己的哈希表
使用通过双链接列表链接实现哈希表类似于使用单链接列表实现哈希表。唯一的区别是,链表的每个节点都具有下一个节点和上一个节点的地址。这将加快从列表中添加和删除元素的过程,因此,时间复杂度将大大降低。
例子:
If we have a Singly linked list:
If we are at 3 and there is a need to remove it, then 2 need to be linked with 4 and as from 3, 2 can’t be accessed as it is singly linked list. So, the list has to be traversed again i.e O(n), but if we have doubly linked list i.e.
2 & 4 can be accessed from 3, hence in O(1), 3 can be removed.
下面是上述方法的实现:
1->2->3->4
输出:
1234