Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue with traverse and reverse order

  • Loading branch information...
commit da2f4280520dce0c3fdd4031e9a998c6504a47c4 1 parent 7c17b4a
@doug-martin authored
Showing with 5 additions and 5 deletions.
  1. +2 −2 index.js
  2. +2 −2 leafy.min.js
  3. +1 −1  package.json
View
4 index.js
@@ -124,9 +124,9 @@
this.traverse(node.right, order, callback);
callback(node.data);
} else if (order === Tree.REVERSE_ORDER) {
- this.traverseWithCondition(node.right, order, callback);
+ this.traverse(node.right, order, callback);
callback(node.data);
- this.traverseWithCondition(node.left, order, callback);
+ this.traverse(node.left, order, callback);
}
}
View
4 leafy.min.js
@@ -1,3 +1,3 @@
-/*! leafy - v0.0.1 - 2013-01-22
+/*! leafy - v0.0.1 - 2013-02-18
* Copyright (c) 2013 Doug Martin; Licensed MIT */
-(function(){"use strict";function e(e){function t(e,t){var n=0;return e>t?1:e<t?-1:t?n:1}var n=e.multiply,r=e.declare({instance:{__printNode:function(t,r){var i=[];e.isUndefinedOrNull(t)?(i.push(n(" ",r)),i.push("~"),console.log(i.join(""))):(this.__printNode(t.right,r+1),i.push(n(" ",r)),i.push(t.data+"\n"),console.log(i.join("")),this.__printNode(t.left,r+1))},constructor:function(e){e=e||{},this.compare=e.compare||t,this.__root=null},insert:function(){throw new Error("Not Implemented")},remove:function(){throw new Error("Not Implemented")},clear:function(){this.__root=null},isEmpty:function(){return!this.__root},traverseWithCondition:function(e,t,n){var i=!0;return e&&(t=t||r.PRE_ORDER,t===r.PRE_ORDER?(i=n(e.data),i&&(i=this.traverseWithCondition(e.left,t,n),i&&(i=this.traverseWithCondition(e.right,t,n)))):t===r.IN_ORDER?(i=this.traverseWithCondition(e.left,t,n),i&&(i=n(e.data),i&&(i=this.traverseWithCondition(e.right,t,n)))):t===r.POST_ORDER?(i=this.traverseWithCondition(e.left,t,n),i&&(i&&(i=this.traverseWithCondition(e.right,t,n)),i&&(i=n(e.data)))):t===r.REVERSE_ORDER&&(i=this.traverseWithCondition(e.right,t,n),i&&(i=n(e.data),i&&(i=this.traverseWithCondition(e.left,t,n))))),i},traverse:function(e,t,n){e&&(t=t||r.PRE_ORDER,t===r.PRE_ORDER?(n(e.data),this.traverse(e.left,t,n),this.traverse(e.right,t,n)):t===r.IN_ORDER?(this.traverse(e.left,t,n),n(e.data),this.traverse(e.right,t,n)):t===r.POST_ORDER?(this.traverse(e.left,t,n),this.traverse(e.right,t,n),n(e.data)):t===r.REVERSE_ORDER&&(this.traverseWithCondition(e.right,t,n),n(e.data),this.traverseWithCondition(e.left,t,n)))},forEach:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this,this.traverse(this.__root,n,function(n){e.call(t,n,this)})},map:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i=new this._static;return this.traverse(this.__root,n,function(n){i.insert(e.call(t,n,this))}),i},filter:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i=new this._static;return this.traverse(this.__root,n,function(n){e.call(t,n,this)&&i.insert(n)}),i},reduce:function(t,n,r){var i=this.toArray(r),s=[i,t];return e.isUndefinedOrNull(n)||s.push(n),e.reduce.apply(e,s)},reduceRight:function(t,n,r){var i=this.toArray(r),s=[i,t];return e.isUndefinedOrNull(n)||s.push(n),e.reduceRight.apply(e,s)},every:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i=!1;return this.traverseWithCondition(this.__root,n,function(n){return i=e.call(t,n,this)}),i},some:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i;return this.traverseWithCondition(this.__root,n,function(n){return i=e.call(t,n,this),!i}),i},toArray:function(e){e=e||r.IN_ORDER;var t=[];return this.traverse(this.__root,e,function(e){t.push(e)}),t},contains:function(e){var t=!1,n=this.__root;while(n!==null){var r=this.compare(e,n.data);r?n=n[r===-1?"left":"right"]:(t=!0,n=null)}return t},find:function(e){var t,n=this.__root;while(n){var r=this.compare(e,n.data);if(!r){t=n.data;break}n=n[r===-1?"left":"right"]}return t},findLessThan:function(e,t){var n=[],i=this.compare;return this.traverseWithCondition(this.__root,r.IN_ORDER,function(r){var s=i(e,r);return!t&&s===0||s===1?(n.push(r),!0):!1}),n},findGreaterThan:function(e,t){var n=[],i=this.compare;return this.traverse(this.__root,r.REVERSE_ORDER,function(r){var s=i(e,r);return!t&&s===0||s===-1?(n.push(r),!0):!1}),n},print:function(){this.__printNode(this.__root,0)}},"static":{PRE_ORDER:"pre_order",IN_ORDER:"in_order",POST_ORDER:"post_order",REVERSE_ORDER:"reverse_order"}}),i=function(){var e=Math.abs,t=function(e){return{data:e,balance:0,left:null,right:null}},i=function(e,t,n){var r=e[n];return e[n]=r[t],r[t]=e,r},s=function(e,t,n){return e[n]=i(e[n],n,t),i(e,t,n)},o=function(e,t,n){var r=t==="left"?"right":"left",i=e[t],s=i[r];s.balance===0?e.balance=i.balance=0:s.balance===n?(e.balance=-n,i.balance=0):(e.balance=0,i.balance=n),s.balance=0},u=function(e,t){var n=t==="left"?"right":"left",r=e[t],u=t==="left"?-1:1;return r.balance===u?(e.balance=r.balance=0,e=i(e,n,t)):(o(e,t,u),e=s(e,n,t)),e},a=function(e,t,n){var r=t==="left"?"right":"left",u=e[r],a=t==="left"?-1:1;return u.balance===-a?(e.balance=u.balance=0,e=i(e,t,r)):u.balance===a?(o(e,r,-a),e=s(e,t,r)):(e.balance=-a,u.balance=a,e=i(e,t,r),n.done=!0),e},f=function(n,r,i,s){if(n===null||n===undefined)n=t(r);else{var o=s(r,n.data)===-1?"left":"right";n[o]=f(n[o],r,i,s),i.done||(n.balance+=o==="left"?-1:1,n.balance===0?i.done=!0:e(n.balance)>1&&(n=u(n,o),i.done=!0))}return n},l=function(t,n,r,i){var s,o,u,f;if(t){o=i(n,t.data);if(o===0){var c=t.left,h=t.right;if(!c||!h)return s=c?"left":"right",u=t[s],u;var p=c;while((h=p.right)!==null)p=h;t.data=p.data,n=p.data}s=i(t.data,n)===-1?"right":"left",t[s]=l(t[s],n,r,i);if(!r.done){f=t.balance+=s==="left"?1:-1;var d=e(f);d===1?r.done=!0:d>1&&(t=a(t,s,r))}}return t};return r.extend({instance:{insert:function(e){var t={done:!1};this.__root=f(this.__root,e,t,this.compare)},remove:function(e){this.__root=l(this.__root,e,{done:!1},this.compare)},__printNode:function(e,t){var r=[];e?(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.balance+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1)):(r.push(n(" ",t)),r.push("~"),console.log(r.join("")))}}})}(),s=function(){function t(t,n){return{data:t,level:n,left:e,right:e}}function i(e){if(e.level!==0&&e.left.level===e.level){var t=e.left;e.left=t.right,t.right=e,e=t}return e}function s(e){if(e.level!==0&&e.right.right.level===e.level){var t=e.right;e.right=t.left,t.left=e,e=t,e.level++}return e}function o(n,r,u){if(n===e)n=t(r,1);else{var a=u(r,n.data)===-1?"left":"right";n[a]=o(n[a],r,u),n=i(n),n=s(n)}return n}var e={level:0,data:null},u=function(t,n,r){var o,a;if(t!==e){var f=r(n,t.data);if(f===0){o=t.left,a=t.right;if(o!==e&&a!==e){var l=o;while(l.right!==e)l=l.right;t.data=l.data,t.left=u(o,l.data,r)}else t=t[o===e?"right":"left"]}else{var c=f===-1?"left":"right";t[c]=u(t[c],n,r)}}if(t!==e){var h=t.level,p=t.left.level,d=t.right.level;if(p<h-1||d<h-1)d>--t.level&&(t.right.level=t.level),t=i(t),t=s(t)}return t};return r.extend({instance:{isEmpty:function(){return this.__root===e||this._super(arguments)},insert:function(t){this.__root||(this.__root=e),this.__root=o(this.__root,t,this.compare)},remove:function(e){this.__root=u(this.__root,e,this.compare)},traverseWithCondition:function(t){var n=!0;return t!==e?this._super(arguments):n},traverse:function(t){t!==e&&this._super(arguments)},contains:function(){return this.__root!==e?this._super(arguments):!1},__printNode:function(e,t){var r=[];!e||!e.data?(r.push(n(" ",t)),r.push("~"),console.log(r.join(""))):(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.level+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1))}}})}(),o=r.extend({instance:{insert:function(e){if(!this.__root)return this.__root={data:e,parent:null,left:null,right:null};var t=this.compare,n=this.__root;while(n!==null){var r=t(e,n.data);if(!r)return;var i=r===-1?"left":"right",s=n[i];if(!s)return n[i]={data:e,parent:n,left:null,right:null};n=s}},remove:function(e){if(this.__root!==null){var t={right:this.__root},n=t,r,i=null,s="right";while(n[s]!==null){r=n,n=n[s];var o=this.compare(e,n.data);o||(i=n),s=o===-1?"left":"right"}i!==null&&(i.data=n.data,r[r.right===n?"right":"left"]=n[n.left===null?"right":"left"]),this.__root=t.right}}}}),u=function(){var e="RED",t="BLACK",i=function(e){return e!==null&&e.red},s=function(e){return{data:e,red:!0,left:null,right:null}},o=function(e,t,n){if(!e)return s(t);var r=n(t,e.data);if(r){var f=r===-1?"left":"right",l=f==="left"?"right":"left";e[f]=o(e[f],t,n);var c=e[f];if(i(c)){var h=e[l];i(h)?(e.red=!0,c.red=!1,h.red=!1):i(c[f])?e=u(e,l):i(c[l])&&(e=a(e,l))}}return e},u=function(e,t){var n=t==="left"?"right":"left",r=e[n];return e[n]=r[t],r[t]=e,e.red=!0,r.red=!1,r},a=function(e,t){var n=t==="left"?"right":"left";return e[n]=u(e[n],n),u(e,t)},f=function(e,t,n,r){if(!e)n.done=!0;else{var s;if(r(t,e.data)===0){if(!e.left||!e.right){var o=e[e.left?"left":"right"];return i(e)?n.done=!0:i(o)&&(o.red=!1,n.done=!0),o}var u=e.right,a;while(u.left!==null)a=u,u=u.left;a&&(a.left=null),e.data=u.data,t=u.data}s=r(t,e.data)===-1?"left":"right",e[s]=f(e[s],t,n,r),n.done||(e=l(e,s,n))}return e},l=function(e,t,n){var r=t==="left"?"right":"left",s=e,o=s[r];i(o)&&(e=u(e,t),o=s[r]);if(o!==null)if(!i(o.left)&&!i(o.right))i(s)&&(n.done=!0),s.red=0,o.red=1;else{var f=s.red,l=e===s;s=(i(o[r])?u:a)(s,t),s.red=f,s.left.red=s.right.red=0,l?e=s:e[t]=s,n.done=!0}return e};return r.extend({instance:{insert:function(e){this.__root=o(this.__root,e,this.compare),this.__root.red=!1},remove:function(e){var t={done:!1},n=f(this.__root,e,t,this.compare);n!==null&&(n.red=0),this.__root=n},__printNode:function(r,i){var s=[];r?(this.__printNode(r.right,i+1),s.push(n(" ",i)),s.push((r.red?e:t)+":"+r.data+"\n"),console.log(s.join("")),this.__printNode(r.left,i+1)):(s.push(n(" ",i)),s.push("~"),console.log(s.join("")))}}})}();return{Tree:r,AVLTree:i,AnderssonTree:s,BinaryTree:o,RedBlackTree:u}}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=e(require("extended")().register("declare",require("declare.js")).register(require("is-extended")).register(require("array-extended")).register(require("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(t,n,r,i,s){return e(t().register("declare",n).register(r).register(i).register(s))}):this.leafy=e(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}).call(this);
+(function(){"use strict";function e(e){function t(e,t){var n=0;return e>t?1:e<t?-1:t?n:1}var n=e.multiply,r=e.declare({instance:{__printNode:function(t,r){var i=[];e.isUndefinedOrNull(t)?(i.push(n(" ",r)),i.push("~"),console.log(i.join(""))):(this.__printNode(t.right,r+1),i.push(n(" ",r)),i.push(t.data+"\n"),console.log(i.join("")),this.__printNode(t.left,r+1))},constructor:function(e){e=e||{},this.compare=e.compare||t,this.__root=null},insert:function(){throw new Error("Not Implemented")},remove:function(){throw new Error("Not Implemented")},clear:function(){this.__root=null},isEmpty:function(){return!this.__root},traverseWithCondition:function(e,t,n){var i=!0;return e&&(t=t||r.PRE_ORDER,t===r.PRE_ORDER?(i=n(e.data),i&&(i=this.traverseWithCondition(e.left,t,n),i&&(i=this.traverseWithCondition(e.right,t,n)))):t===r.IN_ORDER?(i=this.traverseWithCondition(e.left,t,n),i&&(i=n(e.data),i&&(i=this.traverseWithCondition(e.right,t,n)))):t===r.POST_ORDER?(i=this.traverseWithCondition(e.left,t,n),i&&(i&&(i=this.traverseWithCondition(e.right,t,n)),i&&(i=n(e.data)))):t===r.REVERSE_ORDER&&(i=this.traverseWithCondition(e.right,t,n),i&&(i=n(e.data),i&&(i=this.traverseWithCondition(e.left,t,n))))),i},traverse:function(e,t,n){e&&(t=t||r.PRE_ORDER,t===r.PRE_ORDER?(n(e.data),this.traverse(e.left,t,n),this.traverse(e.right,t,n)):t===r.IN_ORDER?(this.traverse(e.left,t,n),n(e.data),this.traverse(e.right,t,n)):t===r.POST_ORDER?(this.traverse(e.left,t,n),this.traverse(e.right,t,n),n(e.data)):t===r.REVERSE_ORDER&&(this.traverse(e.right,t,n),n(e.data),this.traverse(e.left,t,n)))},forEach:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this,this.traverse(this.__root,n,function(n){e.call(t,n,this)})},map:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i=new this._static;return this.traverse(this.__root,n,function(n){i.insert(e.call(t,n,this))}),i},filter:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i=new this._static;return this.traverse(this.__root,n,function(n){e.call(t,n,this)&&i.insert(n)}),i},reduce:function(t,n,r){var i=this.toArray(r),s=[i,t];return e.isUndefinedOrNull(n)||s.push(n),e.reduce.apply(e,s)},reduceRight:function(t,n,r){var i=this.toArray(r),s=[i,t];return e.isUndefinedOrNull(n)||s.push(n),e.reduceRight.apply(e,s)},every:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i=!1;return this.traverseWithCondition(this.__root,n,function(n){return i=e.call(t,n,this)}),i},some:function(e,t,n){if(typeof e!="function")throw new TypeError;n=n||r.IN_ORDER,t=t||this;var i;return this.traverseWithCondition(this.__root,n,function(n){return i=e.call(t,n,this),!i}),i},toArray:function(e){e=e||r.IN_ORDER;var t=[];return this.traverse(this.__root,e,function(e){t.push(e)}),t},contains:function(e){var t=!1,n=this.__root;while(n!==null){var r=this.compare(e,n.data);r?n=n[r===-1?"left":"right"]:(t=!0,n=null)}return t},find:function(e){var t,n=this.__root;while(n){var r=this.compare(e,n.data);if(!r){t=n.data;break}n=n[r===-1?"left":"right"]}return t},findLessThan:function(e,t){var n=[],i=this.compare;return this.traverseWithCondition(this.__root,r.IN_ORDER,function(r){var s=i(e,r);return!t&&s===0||s===1?(n.push(r),!0):!1}),n},findGreaterThan:function(e,t){var n=[],i=this.compare;return this.traverse(this.__root,r.REVERSE_ORDER,function(r){var s=i(e,r);return!t&&s===0||s===-1?(n.push(r),!0):!1}),n},print:function(){this.__printNode(this.__root,0)}},"static":{PRE_ORDER:"pre_order",IN_ORDER:"in_order",POST_ORDER:"post_order",REVERSE_ORDER:"reverse_order"}}),i=function(){var e=Math.abs,t=function(e){return{data:e,balance:0,left:null,right:null}},i=function(e,t,n){var r=e[n];return e[n]=r[t],r[t]=e,r},s=function(e,t,n){return e[n]=i(e[n],n,t),i(e,t,n)},o=function(e,t,n){var r=t==="left"?"right":"left",i=e[t],s=i[r];s.balance===0?e.balance=i.balance=0:s.balance===n?(e.balance=-n,i.balance=0):(e.balance=0,i.balance=n),s.balance=0},u=function(e,t){var n=t==="left"?"right":"left",r=e[t],u=t==="left"?-1:1;return r.balance===u?(e.balance=r.balance=0,e=i(e,n,t)):(o(e,t,u),e=s(e,n,t)),e},a=function(e,t,n){var r=t==="left"?"right":"left",u=e[r],a=t==="left"?-1:1;return u.balance===-a?(e.balance=u.balance=0,e=i(e,t,r)):u.balance===a?(o(e,r,-a),e=s(e,t,r)):(e.balance=-a,u.balance=a,e=i(e,t,r),n.done=!0),e},f=function(n,r,i,s){if(n===null||n===undefined)n=t(r);else{var o=s(r,n.data)===-1?"left":"right";n[o]=f(n[o],r,i,s),i.done||(n.balance+=o==="left"?-1:1,n.balance===0?i.done=!0:e(n.balance)>1&&(n=u(n,o),i.done=!0))}return n},l=function(t,n,r,i){var s,o,u,f;if(t){o=i(n,t.data);if(o===0){var c=t.left,h=t.right;if(!c||!h)return s=c?"left":"right",u=t[s],u;var p=c;while((h=p.right)!==null)p=h;t.data=p.data,n=p.data}s=i(t.data,n)===-1?"right":"left",t[s]=l(t[s],n,r,i);if(!r.done){f=t.balance+=s==="left"?1:-1;var d=e(f);d===1?r.done=!0:d>1&&(t=a(t,s,r))}}return t};return r.extend({instance:{insert:function(e){var t={done:!1};this.__root=f(this.__root,e,t,this.compare)},remove:function(e){this.__root=l(this.__root,e,{done:!1},this.compare)},__printNode:function(e,t){var r=[];e?(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.balance+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1)):(r.push(n(" ",t)),r.push("~"),console.log(r.join("")))}}})}(),s=function(){function t(t,n){return{data:t,level:n,left:e,right:e}}function i(e){if(e.level!==0&&e.left.level===e.level){var t=e.left;e.left=t.right,t.right=e,e=t}return e}function s(e){if(e.level!==0&&e.right.right.level===e.level){var t=e.right;e.right=t.left,t.left=e,e=t,e.level++}return e}function o(n,r,u){if(n===e)n=t(r,1);else{var a=u(r,n.data)===-1?"left":"right";n[a]=o(n[a],r,u),n=i(n),n=s(n)}return n}var e={level:0,data:null},u=function(t,n,r){var o,a;if(t!==e){var f=r(n,t.data);if(f===0){o=t.left,a=t.right;if(o!==e&&a!==e){var l=o;while(l.right!==e)l=l.right;t.data=l.data,t.left=u(o,l.data,r)}else t=t[o===e?"right":"left"]}else{var c=f===-1?"left":"right";t[c]=u(t[c],n,r)}}if(t!==e){var h=t.level,p=t.left.level,d=t.right.level;if(p<h-1||d<h-1)d>--t.level&&(t.right.level=t.level),t=i(t),t=s(t)}return t};return r.extend({instance:{isEmpty:function(){return this.__root===e||this._super(arguments)},insert:function(t){this.__root||(this.__root=e),this.__root=o(this.__root,t,this.compare)},remove:function(e){this.__root=u(this.__root,e,this.compare)},traverseWithCondition:function(t){var n=!0;return t!==e?this._super(arguments):n},traverse:function(t){t!==e&&this._super(arguments)},contains:function(){return this.__root!==e?this._super(arguments):!1},__printNode:function(e,t){var r=[];!e||!e.data?(r.push(n(" ",t)),r.push("~"),console.log(r.join(""))):(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.level+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1))}}})}(),o=r.extend({instance:{insert:function(e){if(!this.__root)return this.__root={data:e,parent:null,left:null,right:null};var t=this.compare,n=this.__root;while(n!==null){var r=t(e,n.data);if(!r)return;var i=r===-1?"left":"right",s=n[i];if(!s)return n[i]={data:e,parent:n,left:null,right:null};n=s}},remove:function(e){if(this.__root!==null){var t={right:this.__root},n=t,r,i=null,s="right";while(n[s]!==null){r=n,n=n[s];var o=this.compare(e,n.data);o||(i=n),s=o===-1?"left":"right"}i!==null&&(i.data=n.data,r[r.right===n?"right":"left"]=n[n.left===null?"right":"left"]),this.__root=t.right}}}}),u=function(){var e="RED",t="BLACK",i=function(e){return e!==null&&e.red},s=function(e){return{data:e,red:!0,left:null,right:null}},o=function(e,t,n){if(!e)return s(t);var r=n(t,e.data);if(r){var f=r===-1?"left":"right",l=f==="left"?"right":"left";e[f]=o(e[f],t,n);var c=e[f];if(i(c)){var h=e[l];i(h)?(e.red=!0,c.red=!1,h.red=!1):i(c[f])?e=u(e,l):i(c[l])&&(e=a(e,l))}}return e},u=function(e,t){var n=t==="left"?"right":"left",r=e[n];return e[n]=r[t],r[t]=e,e.red=!0,r.red=!1,r},a=function(e,t){var n=t==="left"?"right":"left";return e[n]=u(e[n],n),u(e,t)},f=function(e,t,n,r){if(!e)n.done=!0;else{var s;if(r(t,e.data)===0){if(!e.left||!e.right){var o=e[e.left?"left":"right"];return i(e)?n.done=!0:i(o)&&(o.red=!1,n.done=!0),o}var u=e.right,a;while(u.left!==null)a=u,u=u.left;a&&(a.left=null),e.data=u.data,t=u.data}s=r(t,e.data)===-1?"left":"right",e[s]=f(e[s],t,n,r),n.done||(e=l(e,s,n))}return e},l=function(e,t,n){var r=t==="left"?"right":"left",s=e,o=s[r];i(o)&&(e=u(e,t),o=s[r]);if(o!==null)if(!i(o.left)&&!i(o.right))i(s)&&(n.done=!0),s.red=0,o.red=1;else{var f=s.red,l=e===s;s=(i(o[r])?u:a)(s,t),s.red=f,s.left.red=s.right.red=0,l?e=s:e[t]=s,n.done=!0}return e};return r.extend({instance:{insert:function(e){this.__root=o(this.__root,e,this.compare),this.__root.red=!1},remove:function(e){var t={done:!1},n=f(this.__root,e,t,this.compare);return n!==null&&(n.red=0),this.__root=n,e},__printNode:function(r,i){var s=[];r?(this.__printNode(r.right,i+1),s.push(n(" ",i)),s.push((r.red?e:t)+":"+r.data+"\n"),console.log(s.join("")),this.__printNode(r.left,i+1)):(s.push(n(" ",i)),s.push("~"),console.log(s.join("")))}}})}();return{Tree:r,AVLTree:i,AnderssonTree:s,BinaryTree:o,RedBlackTree:u,IN_ORDER:r.IN_ORDER,PRE_ORDER:r.PRE_ORDER,POST_ORDER:r.POST_ORDER,REVERSE_ORDER:r.REVERSE_ORDER}}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=e(require("extended")().register("declare",require("declare.js")).register(require("is-extended")).register(require("array-extended")).register(require("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(t,n,r,i,s){return e(t().register("declare",n).register(r).register(i).register(s))}):this.leafy=e(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}).call(this);
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "leafy",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "Different Tree Implementations",
"main": "index.js",
"scripts": {
Please sign in to comment.
Something went wrong with that request. Please try again.