Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6vDJ5fWY5uEZaJFNi
32 lines
409 B
Plaintext
32 lines
409 B
Plaintext
Delete case 1: a leaf
|
|
=====================
|
|
|
|
before:
|
|
50
|
|
L: 30
|
|
L: 20
|
|
R: 40
|
|
L: 35
|
|
R: 70
|
|
L: 60
|
|
R: 65
|
|
R: 80
|
|
|
|
delete 20:
|
|
at 50: 20 < 50, go left
|
|
at 30: 20 < 30, go left
|
|
at 20: equal, found after 3 nodes
|
|
leaf: return null to the parent
|
|
|
|
after:
|
|
50
|
|
L: 30
|
|
R: 40
|
|
L: 35
|
|
R: 70
|
|
L: 60
|
|
R: 65
|
|
R: 80
|
|
|
|
inorder: [30, 35, 40, 50, 60, 65, 70, 80]
|