No probs Christina.
I look forward to more goodies from you.
A note on the recursion idiom in Computer Science...
I am in the camp that recursion is a nasty antipattern.
I never use it my own code and never will.
Recursion can be reimplemented with a simple loop.
(I plan to write a post on this soon with a more indepth explanation)
The recursive insert() function blows up on my machine before 16,000 nodes.
Here is an example of the insert() recursive function, rewritten as an iterative function...
(Fun exercise: See if you can rewrite the rest of the recursive functions in this BSTClass ;-)
/**
@method
add a new node to the BST
an implementation without recursion
@pros vs recursion
4 times faster in performance tests
no stack overflow exception thrown (called a RangeError in JavaScript)
- so no limit to BST node size
a single method
easier to grok
@param {number} num - the data value of the node
*/insertIterativeNum(num){constnewNode=newNode(num);if(this.root===null){//first base casethis.root=newNode;return;}lett=this.root;//temporary nodewhile(true){if(newNode.data<t.data){if(t.left===null){t.left=newNode;break;}else{t=t.left;}}else{if(t.right===null){t.right=newNode;break;}else{t=t.right}}}};
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
No probs Christina.
I look forward to more goodies from you.
A note on the recursion idiom in Computer Science...
I am in the camp that recursion is a nasty antipattern.
I never use it my own code and never will.
Recursion can be reimplemented with a simple loop.
(I plan to write a post on this soon with a more indepth explanation)
The recursive insert() function blows up on my machine before 16,000 nodes.
Here is an example of the insert() recursive function, rewritten as an iterative function...
(Fun exercise: See if you can rewrite the rest of the recursive functions in this BSTClass ;-)