Skip to content

RedBlack.js Question? #3

@jeffreywang1988

Description

@jeffreywang1988
		else if (tree.right == null || tree.right.phantomLeaf)
		{
			this.cmd("SetText",  0,"Node to delete has no right child.  \nSet parent of deleted node to left child of deleted node.");
			if (tree.right != null)
			{
				this.cmd("Delete", tree.right.graphicID);
				tree.right = null;					
			}
			if (tree.parent != null)
			{
				this.cmd("Disconnect", tree.parent.graphicID, tree.graphicID);
				this.cmd("Connect", tree.parent.graphicID, tree.left.graphicID, LINK_COLOR);
				this.cmd("Step");
				this.cmd("Delete", tree.graphicID);
				if (leftchild)
				{
					tree.parent.left = tree.left;
					if (needFix)
					{
						tree.parent.left.blackLevel++;
						this.fixNodeColor(tree.parent.left);
						this.fixExtraBlack(tree.parent.left);
						this.resizeTree();
					}
					else
					{
						this.cmd("SetText", 0, "Deleted node was red.  No tree rotations required.");									
						this.resizeTree();
							
					}
				}
				else
				{
					tree.parent.right = tree.left;
					if (needFix)
					{
						tree.parent.right.blackLevel++;
						this.fixNodeColor(tree.parent.right);
						this.fixExtraBlack(tree.parent.left); // here is my question. 
						this.resizeTree();
					}
					else
					{
						this.cmd("SetText", 0, "Deleted node was red.  No tree rotations required.");									
						this.resizeTree();								
					}
				}
				tree.left.parent = tree.parent;
			}
			else
			{
				this.cmd("Delete" , tree.graphicID);
				this.treeRoot = tree.left;
				this.treeRoot.parent = null;
				if (this.treeRoot.blackLevel == 0)
				{
					this.treeRoot.blackLevel = 1;
					this.fixNodeColor(this.treeRoot);
				}
			}
		}//In 1145 line, Why the code is this.fixExtraBlack(tree.parent.left);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions