Skip to content

Commit e1d804a

Browse files
author
Kurt von Laven
committed
Document return value of insert methods.
1 parent 970a893 commit e1d804a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ key is not present in this tree.
4343
#### insert(key, value)
4444

4545
Inserts the given key, value pair in this tree. Creates a new node with the
46-
given key and value and inserts it in the appropriate position. Throws an
47-
exception if the given key is already present in this tree.
46+
given key and value and inserts it in the appropriate position. Returns the
47+
created node. Throws an exception if the given key is already present in this
48+
tree.
4849

4950
#### remove(key)
5051

@@ -112,7 +113,8 @@ Returns null if there is no such node.
112113

113114
Inserts the given key, value pair in the subtree rooted at this node. Creates
114115
a new node with the given key and value and inserts it in the appropriate
115-
position. Throws an exception if the given key is already in this subtree.
116+
position. Returns the created node. Throws an exception if the given key is
117+
already in this subtree.
116118

117119
#### remove()
118120

binary-search-tree.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ BinarySearchTree.prototype.Node.prototype.get = function (key) {
131131

132132
/* Inserts the given key, value pair in the subtree rooted at this node. Creates
133133
* a new node with the given key and value and inserts it in the appropriate
134-
* position. Throws an exception if the given key is already in this subtree.
134+
* position. Returns the created node. Throws an exception if the given key is
135+
* already in this subtree.
135136
*/
136137
BinarySearchTree.prototype.Node.prototype.insert = function (key, value) {
137138
for (var currNode = this; true; ) {
@@ -289,8 +290,9 @@ BinarySearchTree.prototype.get = function (key) {
289290
};
290291

291292
/* Inserts the given key, value pair in this tree. Creates a new node with the
292-
* given key and value and inserts it in the appropriate position. Throws an
293-
* exception if the given key is already present in this tree.
293+
* given key and value and inserts it in the appropriate position. Returns the
294+
* created node. Throws an exception if the given key is already present in this
295+
* tree.
294296
*/
295297
BinarySearchTree.prototype.insert = function (key, value) {
296298
if (this.root === null) {

0 commit comments

Comments
 (0)