/
bstree.min.js
1 lines (1 loc) · 2.01 KB
/
bstree.min.js
1
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.BSTree=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){b.exports=a("./lib/bstree.js")},{"./lib/bstree.js":2}],2:[function(a,b){function BSTree(a){this._comp=a||function(a,b){return b>a},this.length=0}function c(a,b,d){var e=a[b];e?this._comp(d,e.data)?c.call(this,e,"left",d):c.call(this,e,"right",d):a[b]={data:d,parent:a}}function d(a,b){for(;a[b];)a=a[b];return a}function e(a){if(this.root){var b=d(this.root,a);return b.parent===this&&(a="root"),g(b.parent,a),this.length--,b.data}return void 0}function f(a){return this.root?d(this.root,a).data:void 0}function g(a,b){var c=a[b];if(void 0===c.left)c=a[b]=c.right;else if(void 0===c.right)c=a[b]=c.left;else{var e=d(c.right,"left");c.data=e.data,a=e.parent,a===c?a.right=e.right:a.left=e.right,c=e.right,e.parent=a}c&&(c.parent=a)}function h(a,b,c){var d=a[b];return d?this._comp(c,d.data)?h.call(this,d,"left",c):this._comp(d.data,c)?h.call(this,d,"right",c):c===d.data?(g(a,b),this.length--,c):h.call(this,d,"right",c):void 0}BSTree.prototype={constructor:BSTree,add:function(a){c.call(this,this,"root",a),this.length++},remove:function(a){return h.call(this,this,"root",a)},top:function(){return f.call(this,"right")},bottom:function(){return f.call(this,"left")},removeTop:function(){return e.call(this,"right")},removeBottom:function(){return e.call(this,"left")}},b.exports=BSTree},{}]},{},[1])(1)});