Advertisement
vencinachev

BinaryTreeNode

Sep 8th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. class BinTreeNode<T>
  2.     {
  3.         private T value;
  4.         private bool hasparent;
  5.         private BinTreeNode<T> leftChild;
  6.         private BinTreeNode<T> rightChild;
  7.  
  8.  
  9.         public T Value
  10.         {
  11.             get
  12.             {
  13.                 return this.value;
  14.             }
  15.             set
  16.             {
  17.                 if (this.value == null)
  18.                 {
  19.                     throw new ArgumentNullException();
  20.                 }
  21.                 this.value = value;
  22.             }
  23.         }
  24.  
  25.         public BinTreeNode<T> LeftChild
  26.         {
  27.             get
  28.             {
  29.                 return this.leftChild;
  30.             }
  31.             set
  32.             {
  33.                 if (value == null)
  34.                 {
  35.                     return;
  36.                 }
  37.                 if (value.hasparent)
  38.                 {
  39.                     throw new ArgumentException();
  40.                 }
  41.                 value.hasparent = true;
  42.                 this.leftChild = value;
  43.             }
  44.         }
  45.  
  46.         public BinTreeNode<T> RightChild
  47.         {
  48.             get
  49.             {
  50.                 return this.rightChild;
  51.             }
  52.             set
  53.             {
  54.                 if (value == null)
  55.                 {
  56.                     return;
  57.                 }
  58.                 if (value.hasparent)
  59.                 {
  60.                     throw new ArgumentException();
  61.                 }
  62.                 value.hasparent = true;
  63.                 this.rightChild = value;
  64.             }
  65.         }
  66.  
  67.         public BinTreeNode(T value, BinTreeNode<T> leftChild, BinTreeNode<T> rightChild)
  68.         {
  69.             this.Value = value;
  70.             this.LeftChild = leftChild;
  71.             this.RightChild = rightChild;
  72.         }
  73.  
  74.         public BinTreeNode(T value) : this(value, null, null)
  75.         {
  76.         }
  77.  
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement