|
291 | 291 | , L.nil.next.next.next.next.key, '->'
|
292 | 292 | , L.nil.next.next.next.next.next.key
|
293 | 293 | )
|
| 294 | + |
| 295 | +# CLRS Section 11.2 - Hash Table with Chaining |
| 296 | +from data_structures.p258_hash_table_chaining import HashTableChaining |
| 297 | + |
| 298 | +print('\nSection 11.2 - Hash Table with Chaining') |
| 299 | + |
| 300 | +T = HashTableChaining(9) # cf. Exercise 11.2-2, p. 261 |
| 301 | +T.chained_hash_insert(ListNode(5)) |
| 302 | +T.chained_hash_insert(ListNode(28)) |
| 303 | +T.chained_hash_insert(ListNode(19)) |
| 304 | +T.chained_hash_insert(ListNode(15)) |
| 305 | +T.chained_hash_insert(ListNode(20)) |
| 306 | +T.chained_hash_insert(ListNode(33)) |
| 307 | +T.chained_hash_insert(ListNode(12)) |
| 308 | +T.chained_hash_insert(ListNode(17)) |
| 309 | +T.chained_hash_insert(ListNode(10)) |
| 310 | +print('\nafter chained_hash_insert\'s:') |
| 311 | +for i in range(0, len(T.T)): |
| 312 | + if T.T[i].head is None: |
| 313 | + print(f'{i}: {T.T[i].head}') |
| 314 | + else: |
| 315 | + str = f'{i}: ' |
| 316 | + pointer = T.T[i].head |
| 317 | + while(pointer is not None): |
| 318 | + str += f'{pointer.key} -> ' |
| 319 | + pointer = pointer.next |
| 320 | + str += 'None' |
| 321 | + print(str) |
| 322 | +delete_node = T.chained_hash_search(19) |
| 323 | +T.chained_hash_delete(delete_node) |
| 324 | +print('after chained_hash_delete(19):') |
| 325 | +for i in range(0, len(T.T)): |
| 326 | + if T.T[i].head is None: |
| 327 | + print(f'{i}: {T.T[i].head}') |
| 328 | + else: |
| 329 | + str = f'{i}: ' |
| 330 | + pointer = T.T[i].head |
| 331 | + while(pointer is not None): |
| 332 | + str += f'{pointer.key} -> ' |
| 333 | + pointer = pointer.next |
| 334 | + str += 'None' |
| 335 | + print(str) |
0 commit comments