trekhleb / trekhleb/javascript-algorithms
replaceChild in BinaryTreeNode, the replacementNode's parent is incorrect
Ouverte
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 197k
- Forks
- 31k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
const leftNode = new BinaryTreeNode(1);
const rightNode = new BinaryTreeNode(3);
const rootNode = new BinaryTreeNode(2);
rootNode
.setLeft(leftNode)
.setRight(rightNode);
expect(rootNode.traverseInOrder()).toEqual([1, 2, 3]);
const replacementNode = new BinaryTreeNode(5);
rightNode.setRight(replacementNode);
expect(rootNode.traverseInOrder()).toEqual([1, 2, 3, 5]);
expect(rootNode.replaceChild(rootNode.right, rootNode.right.right)).toBe(true);
expect(rootNode.right.parent.value).toBe(2); // Expected: 2, but Received: 3
It's better to set replacementNode's parent to this.left/this.right in replaceChild method of BinaryTreeNode
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Start at BinaryTreeNode.replaceChild and reproduce the case with the left, right, and replacement nodes shown in the issue. Verify the parent value after replacement and add or update the relevant BinaryTreeNode test so the replacement node is attached to the correct parent.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- data
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 45/100