File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ public class ImmutableBinaryTree < T >
2+ {
3+ public T Value { get ; }
4+ public ImmutableBinaryTree < T > ? Left { get ; }
5+ public ImmutableBinaryTree < T > ? Right { get ; }
6+
7+ public ImmutableBinaryTree ( T value , ImmutableBinaryTree < T > ? left = null , ImmutableBinaryTree < T > ? right = null )
8+ {
9+ Value = value ;
10+ Left = left ;
11+ Right = right ;
12+ }
13+
14+ public ImmutableBinaryTree < T > AddLeft ( T newValue )
15+ {
16+ return new ImmutableBinaryTree < T > ( Value , new ImmutableBinaryTree < T > ( newValue ) , Right ) ;
17+ }
18+
19+ public ImmutableBinaryTree < T > AddRight ( T newValue )
20+ {
21+ return new ImmutableBinaryTree < T > ( Value , Left , new ImmutableBinaryTree < T > ( newValue ) ) ;
22+ }
23+
24+ public ImmutableBinaryTree < T > ReplaceLeft ( ImmutableBinaryTree < T > ? newLeft )
25+ {
26+ return new ImmutableBinaryTree < T > ( Value , newLeft , Right ) ;
27+ }
28+
29+ public ImmutableBinaryTree < T > ReplaceRight ( ImmutableBinaryTree < T > ? newRight )
30+ {
31+ return new ImmutableBinaryTree < T > ( Value , Left , newRight ) ;
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments