Created Tree + Tree Node
This commit is contained in:
parent
27c51969f8
commit
e1a85f7b53
25
C#/Datastructures/BinarySearchTree/Tree.cs
Normal file
25
C#/Datastructures/BinarySearchTree/Tree.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using C_.Datastructures.BinarySearchTree;
|
||||
using System;
|
||||
|
||||
namespace C_.Datastructures.BinarySearchTree
|
||||
{
|
||||
internal class Tree<T> where T:IComparable
|
||||
{
|
||||
public TreeNode<T>? Head { get; set; }
|
||||
public int Count { get; set; }
|
||||
|
||||
public Tree<T> Create(){
|
||||
//Create a new Tree with no Head
|
||||
return new Tree<T>{
|
||||
Head = null,
|
||||
Count = 0
|
||||
};
|
||||
}
|
||||
public Tree<T> Create(T? value){
|
||||
//Create a new Tree with Head
|
||||
return new Tree<T>{
|
||||
Head = TreeNode<T>.Create(value)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
28
C#/Datastructures/BinarySearchTree/TreeNode.cs
Normal file
28
C#/Datastructures/BinarySearchTree/TreeNode.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using C_.Datastructures.Generic;
|
||||
|
||||
namespace C_.Datastructures.BinarySearchTree
|
||||
{
|
||||
internal class TreeNode<T>:DirectedNode<T, TreeNode<T>>
|
||||
{
|
||||
//All properties inherited from base class
|
||||
public static TreeNode<T> Create(T? value){
|
||||
//Create a new node without any children
|
||||
return new TreeNode<T>{
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
|
||||
public static TreeNode<T> Create(T? value, TreeNode<T>? left, TreeNode<T>? right){
|
||||
//Create a new node with the option of having children
|
||||
return new TreeNode<T>{
|
||||
Value = value,
|
||||
Left = left,
|
||||
Right = right
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user