// Validate to validate whether b is a valid binary search tree.
// return true if it's valid, false if it's not match the property of binary search tree.
Validate to validate whether b is a valid binary search tree.
return true if it's valid, false if it's not match the property of binary search tree.
// Validate to validate whether b is a valid binary search tree . // return true if it ' s valid false if it ' s not match the property of binary search tree .
func (b BinarySearchTree) Validate() bool {
	if b.Empty() {
		return true
	}
	var walked []int
	b.InorderTreeWalk(func(key int, payload interface{}) {
		walked = append(walked, key)
	})
	if len(walked) != b.count {
		return false
	}
	for i := 1; i < len(walked); i++ {
		if walked[i-1] > walked[i] {
			return false
		}
	}
	return true
}
func ( b BinarySearchTree ) Validate ( ) bool { if b . Empty ( ) { return true } var walked [ ] int b . InorderTreeWalk ( func ( key int , payload interface { } ) { walked = append ( walked , key ) } ) if len ( walked ) != b . count { return false } for i := 1 ; i < len ( walked ) ; i ++ { if walked [ i - 1 ] > walked [ i ] { return false } } return true }
Validate to validate whether b is a valid binary search tree.
Validate to validate whether b is a valid binary search tree .