We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4e73c5c commit a6447ddCopy full SHA for a6447dd
bst.html
@@ -120,7 +120,20 @@ <h2>Breadth First Search</h2>
120
<p><strong>Question:</strong> How do you implement Breadth First Search</p>
121
<p><strong>Answer:</strong></p>
122
<pre><code>
123
-
+BinarySearchTree.prototype.breadthFirstSearch = function() {
124
+ var queue = [];
125
+ queue.push(this);
126
+ while (queue.length) {
127
+ var node = queue.shift();
128
+ console.log(node.value);
129
+ if (node.left) {
130
+ queue.push(node.left);
131
+ }
132
+ if (node.right) {
133
+ queue.push(node.right);
134
135
136
+};
137
</code></pre>
138
<p>ref: <a href="http://stackoverflow.com/a/13633354/1535443">stackoverflow</a></p>
139
<p>ref: <a href="https://github.com/duereg/js-algorithms">js algorithms</a></p>
0 commit comments