C
C#14mo ago
Tundrin

❔ Help with AVL Binary Tree implementation

I'm working on a uni assignment implementing an AVL Binary Tree and keep getting errors even tho I think it's correct. Could someone give me a hand? it may be due tonight....
16 Replies
Tundrin
Tundrin14mo ago
oh yeah I should probably mention that my issue is to do with the rotations (I think specifically the LR and RL ones)
Anchy
Anchy14mo ago
parent.left is probably null
Tundrin
Tundrin14mo ago
then why is it trying to rotate right?
Anchy
Anchy14mo ago
I meant parent.right brain malfunction if pivot is null then parent.right is null no wait i was right
Tundrin
Tundrin14mo ago
yeah
Anchy
Anchy14mo ago
im reading the wrong line now
Tundrin
Tundrin14mo ago
lol, vibe
Anchy
Anchy14mo ago
double brain malfunction, its been a long day yeah so if its reporting pivot is null, then parent.left is null; since you are assigning it on the previous line
Tundrin
Tundrin14mo ago
I think it's an issue with choosing which rotations to call, so this code, but idk how
Anchy
Anchy14mo ago
im too cooked to read any of this, I hope you find the help you need lol
Tundrin
Tundrin14mo ago
all g, thanks for trying
Tundrin
Tundrin14mo ago
if anyone wants to know, been doing some diagnostics, trying to visualize what it's doing, when the following nodes are inserted I get a binary tree that looks like the attached diagram.
Tundrin
Tundrin14mo ago
which is obviously extremely correct and valid
Tundrin
Tundrin14mo ago
here is a diagram from https://www.cs.usfca.edu/~galles/visualization/AVLtree.html with the same inputs
Tundrin
Tundrin14mo ago
the previous state of the tree was this, which is correct...
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.