Created Tree + Tree Node

This commit is contained in:
Luke Else 2022-04-04 21:36:04 +01:00
parent 27c51969f8
commit e1a85f7b53
2 changed files with 53 additions and 0 deletions

View 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)
};
}
}
}

View 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
};
}
}
}