Skip to content

Commit dd6e29b

Browse files
committed
added empty tree constraint
1 parent 0852027 commit dd6e29b

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

chapter08/01-BinarySearchTree.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,29 @@ function BinarySearchTree() {
103103
};
104104

105105
var minNode = function (node) {
106-
while (node && node.left !== null) {
107-
node = node.left;
108-
}
106+
if (node){
107+
while (node && node.left !== null) {
108+
node = node.left;
109+
}
109110

110-
return node.key;
111+
return node.key;
112+
}
113+
return null;
111114
};
112115

113116
this.max = function() {
114117
return maxNode(root);
115118
};
116119

117120
var maxNode = function (node) {
118-
while (node && node.right !== null) {
119-
node = node.right;
120-
}
121+
if (node){
122+
while (node && node.right !== null) {
123+
node = node.right;
124+
}
121125

122-
return node.key;
126+
return node.key;
127+
}
128+
return null;
123129
};
124130

125131
this.remove = function(element){

0 commit comments

Comments
 (0)