PacktPublishing / Learning-JavaScript-Data-Structures-and-Algorithms-Third-Edition

Learning JavaScript Data Structures and Algorithms (Third Edition), published by Packt
MIT License
1.05k stars 428 forks source link

Doubt?return this.rotationLR(node.left); #7

Open canfeit opened 4 years ago

canfeit commented 4 years ago

https://github.com/PacktPublishing/Learning-JavaScript-Data-Structures-and-Algorithms-Third-Edition/blob/2cedcaf8479a90400812bc85f1edd0e5db2debbf/LearningJavaScriptDataStructuresandAlgorithmsThirdEdition_Code/src/ts/data-structures/avl-tree.ts#L181 I think this line should be:

return this.rotationLR(node);

Why use left?

hefeng6500 commented 2 years ago

https://github.com/PacktPublishing/Learning-JavaScript-Data-Structures-and-Algorithms-Third-Edition/blob/2cedcaf8479a90400812bc85f1edd0e5db2debbf/LearningJavaScriptDataStructuresandAlgorithmsThirdEdition_Code/src/ts/data-structures/avl-tree.ts#L181

I think this line should be:

return this.rotationLR(node);

Why use left?

Hi,canfeit!

The author is correct,the function of rotationLR params is node.left not node, why ? maybe you should review rotationLR Function details.

first, use node.left rotate to the left, node.left.right get balanced second, use node rotate to the right, node.left get balanced

rotationLR(node) {
    node.left = this.rotationRR(node.left);
    return this.rotationLL(node);
  }