File tree Expand file tree Collapse file tree 1 file changed +10
-15
lines changed
Advanced.Algorithms.Tests/DataStructures/Tree/TestHelpers Expand file tree Collapse file tree 1 file changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -11,29 +11,24 @@ public class BinarySearchTreeTester<T> where T:IComparable
1111 {
1212
1313 public static bool VerifyIsBinarySearchTree ( IBSTNode < T > node )
14+ {
15+ return VerifyIsBinarySearchTree ( node , int . MinValue , int . MaxValue ) ;
16+ }
17+
18+ public static bool VerifyIsBinarySearchTree ( IBSTNode < T > node , int lowerBound , int upperBound )
1419 {
1520 if ( node == null )
1621 {
1722 return true ;
1823 }
1924
20- if ( node . Left != null )
21- {
22- if ( node . Left . Value . CompareTo ( node . Value ) > 0 )
23- {
24- return false ;
25- }
26- }
27-
28- if ( node . Right != null )
25+ if ( node . Value >= upperBound || node . Value <= lowerBound )
2926 {
30- if ( node . Right . Value . CompareTo ( node . Value ) < 0 )
31- {
32- return false ;
33- }
27+ return false ;
3428 }
35- return VerifyIsBinarySearchTree ( node . Left ) &&
36- VerifyIsBinarySearchTree ( node . Right ) ;
29+
30+ return VerifyIsBinarySearchTree ( node . Left , lowerBound , node . Value ) &&
31+ VerifyIsBinarySearchTree ( node . Right , node . Value , upperBound ) ;
3732 }
3833 }
3934}
You can’t perform that action at this time.
0 commit comments