Skip to content

Commit bf76e82

Browse files
committed
chk for empty tree
1 parent 85dba87 commit bf76e82

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Advanced.Algorithms/DataStructures/Tree/B+Tree.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public T Max
7575
{
7676
get
7777
{
78+
if (Root == null) return default(T);
79+
7880
var maxNode = findMaxNode(Root);
7981
return maxNode.Keys[maxNode.KeyCount - 1];
8082
}
@@ -84,6 +86,8 @@ public T Min
8486
{
8587
get
8688
{
89+
if (Root == null) return default(T);
90+
8791
var minNode = BottomLeftNode;
8892
return minNode.Keys[0];
8993
}

Advanced.Algorithms/DataStructures/Tree/BTree.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public T Max
100100
{
101101
get
102102
{
103+
if (Root == null) return default(T);
104+
103105
var maxNode = findMaxNode(Root);
104106
return maxNode.Keys[maxNode.KeyCount - 1];
105107
}
@@ -109,6 +111,8 @@ public T Min
109111
{
110112
get
111113
{
114+
if (Root == null) return default(T);
115+
112116
var minNode = findMinNode(Root);
113117
return minNode.Keys[0];
114118
}

0 commit comments

Comments
 (0)