Skip to content

Commit b1a7c5c

Browse files
authored
Merge pull request #45 from ewdlop/ewdlop-patch-35
Update ImmutableBinaryTree.cs
2 parents bf5bc96 + 692e70a commit b1a7c5c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

C#/ChatGPT/ImmutableBinaryTree.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@ public ImmutableBinaryTree<T> ReplaceRight(ImmutableBinaryTree<T>? newRight)
3030
{
3131
return new ImmutableBinaryTree<T>(Value, Left, newRight);
3232
}
33+
34+
// Replace the root value but keep structure
35+
public ImmutableBinaryTree<T> ReplaceRootValue(T newValue)
36+
{
37+
return new ImmutableBinaryTree<T>(newValue, Left, Right);
38+
}
39+
40+
// Example Insert pattern: replace root on match
41+
public ImmutableBinaryTree<T> InsertAtRoot(T newValue)
42+
{
43+
return ReplaceRootValue(newValue);
44+
}
3345
}

0 commit comments

Comments
 (0)