Created Max and Min functions for Binary Tree

This commit is contained in:
Luke Else 2022-04-14 20:13:35 +01:00
parent a2c7326e4b
commit 6906d2e764

View File

@ -65,6 +65,32 @@ namespace C_.Datastructures.BinaryTree
return default;
}
public TreeNode<T>? Min(TreeNode<T>? node)
{//Returns the Minimum node from a given subtree
if(node == default)
return default;
while(true){
if (node!.Left == default)
return node;
node = node.Left;
}
}
public TreeNode<T>? Max(TreeNode<T>? node)
{//Returns the Minimum node from a given subtree
if(node == default)
return default;
while(true){
if (node!.Right == default)
return node;
node = node.Right;
}
}
private TreeNode<T>? Traverse(T value, TreeNode<T> node)
{//T is comparable so use methods to determine which way to traverse
if(node == default)