trekhleb / javascript-algorithms

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
MIT License
185.13k stars 29.86k forks source link

read-black-tree #939

Open 15890182384 opened 1 year ago

15890182384 commented 1 year ago

let tree = new RedBlackTree(); tree.insert(5); tree.insert(10); tree.insert(8); At this time, the parent pointer of 10 is null;

runnyren commented 1 year ago

let tree = new RedBlackTree(1); tree.insert(5); tree.insert(10); tree.insert(8); At this time, the parent pointer of 10 is null;

Skilly55 commented 1 year ago

let tree = new RedBlackTree(1); tree.insert(5); tree.insert(10); tree.insert(8);

if (!tree.root.right || !tree.root.right.right) { console.error("The parent pointer of 10 is null"); }

This version of the code uses a conditional statement to check if the parent pointer of 10 is null, and if so, it logs an error message.