Created Max and Min functions for Binary Tree
This commit is contained in:
parent
a2c7326e4b
commit
6906d2e764
@ -65,6 +65,32 @@ namespace C_.Datastructures.BinaryTree
|
|||||||
return default;
|
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)
|
private TreeNode<T>? Traverse(T value, TreeNode<T> node)
|
||||||
{//T is comparable so use methods to determine which way to traverse
|
{//T is comparable so use methods to determine which way to traverse
|
||||||
if(node == default)
|
if(node == default)
|
||||||
|
Loading…
Reference in New Issue
Block a user