text: ﻿(function(){var h=!1,f={$namespace:function(a){if(!a)return window;var c,b=a.split("."),d;d=window;a=0;for(c=b.length;a<c;a++){var e=b[a];d[e]=d[e]||{};d=d[e]}return d},$package:function(a,c){var b;"function"==typeof a?(c=a,b=window):"string"==typeof a?b=this.$namespace(a):"object"==typeof a&&(b=a);c.call(b,this)},"extends":function(a,c,b){function d(b,a,c){var g=!0;!1===c&&(g=!1);if(a instanceof Array){var e=0;for(c=a.length;e<c;e++)d(b,a[e],g)}for(e in a)!g&&e in b||(b[e]=a[e]);return b}a=d(a,c,b);for(var e in c)delete a[e];return a},setDebug:function(a){h=value},log:function(a){console.log(a)},warn:function(a){console.warn(a)},error:function(a){console.error(a)},version:"0.0.1"};f.isDebug=h;window.Algorithm=f;window.AL=f;"function"===typeof define&&define(function(){return f})})();Algorithm.$package(function(h){var f={BubbleSort:function(a){for(var c=0;c<a.length-1;c++)for(var b=0;b<a.length-c-1;b++)if(a[b]>a[b+1]){var d=a,e=b,g=b+1,f=d[g];d[g]=d[e];d[e]=f}return a},SelectionSort:function(a){for(var c=0;c<a.length-1;c++)for(var b=c+1;b<a.length;b++)if(a[c]>a[b]){var d=a,e=c,g=d[b];d[b]=d[e];d[e]=g}return a},insertionSort:function(a,c){for(var b=c=c||1;b<a.length;b++){var d=a[b];for(j=b-c;0<=j&&d<a[j];)a[j+c]=a[j],j--;a[j+c]=d}return a},shellSort:function(a,c){c=c||[1,4,10];for(var b=0;b<c.length;b++)f.insertionSort(a,c[b]);return a},mergeSort:function(a){function c(b){if(1>=b.length)return b;var a=parseInt(b.length/2),e=b.slice(0,a);b=b.slice(a);e=c(e);b=c(b);for(a=[];e.length&&b.length;)e[0]<b[0]?a.push(e.shift()):a.push(b.shift());for(;e.length;)a.push(e.shift());for(;b.length;)a.push(b.shift());return a}return c(a)},quickSort:function(a){function c(a){if(1>=a.length)return a;for(var b=[],e=[],g=1;g<a.length;g++)a[g]<a[0]?b.push(a[g]):e.push(a[g]);return c(b).concat(a[0],c(e))}return c(a)}};h.sort=f});Algorithm.$package(function(h){var f={LinkedList:function(){var a=this;a._head={content:"head",next:null};a.lastNode=a._head;a.length=0;a.newNode=function(c,b){if(b){var d={content:c,next:b.next};b.next=d}else d={content:c,next:null},a.lastNode.next=d,a.lastNode=d;a.length++};a.find=function(c){for(var b=a._head;b.content!=c&&(b=b.next,null!=b)&&(b.content!=a.lastNode.content||b.next!=a.lastNode.next););return b};a.removeNode=function(c){for(var b=a._head,d,e=!0;;)if(d=b,b=b.next,null==b){e=!1;break}else if(b.content==c)break;else if(b.content==a.lastNode.content&&b.next==a.lastNode.next){e=!1;break}e&&(d.next=b.next,b.content=null,b.next=null,a.length--)}},doubleLinkList:function(){var a=this;f.LinkedList.call(a);a._head.prev=null;a.newNode=function(c,b){if(b){var d={content:c,next:b.next,prev:b};null!=b.next&&(b.next.prev=d);b.next=d}else d={content:c,next:null,prev:a.lastNode},a.lastNode.next=d,a.lastNode=d;a.length++};a.removeNode=function(c){for(var b=a._head,d,e=!0;;)if(d=b,b=b.next,null==b){e=!1;break}else if(b.content==c)break;else if(b.content==a.lastNode.content&&b.next==a.lastNode.next){e=!1;break}e&&(d.next=b.next,null!=b.next&&(b.next.prev=d),b.content=null,b.next=null,a.length--)}}};f.doubleLinkList.prototype=new f.LinkedList;f.LoopLinkList=function(){var a=this;f.LinkedList.call(a);a.lastNode.next=a._head;a.newNode=function(c,b){if(b){var d={content:c,next:b.next};b.next=d}else d={content:c,next:a._head},a.lastNode.next=d,a.lastNode=d;a.length++}};f.LoopLinkList.prototype=new f.LinkedList;h.linkList=f});Algorithm.$package(function(h){h.Tree={BST:function(){var f=this;f.root=null;f.tree=f.root;f.insert=function(a){var c={data:a,count:1,left:null,right:null};if(null==f.root)f.root=c;else for(var b=f.root,d;;)if(d=b,a<d.data)if(null==b.left){b.left=c;break}else b=b.left;else if(a>d.data)if(null==b.right){b.right=c;break}else b=b.right;else{b.count++;break}};f.traversals=function(a){function c(a){null!=a&&(e.push(a.data),c(a.left),c(a.right))}function b(a){null!=a&&(b(a.left),e.push(a.data),b(a.right))}function d(a){null!=a&&(d(a.left),d(a.right),e.push(a.data))}var e=[];"preOrder"==a?c(f.root):"inOrder"==a?b(f.root):"postOrder"==a&&d(f.root);return e};f.search=function(a){function c(a){null!=a.right?c(a.right):e=a}function b(a){null!=a.left?b(a.left):e=a}function d(b){for(;;)if(b.data==a){e=b;break}else if(b.data>a)if(null!=b.left)b=b.left;else{e=!1;break}else if(b.data<a)if(null!=b.right)b=b.right;else{e=!1;break}}var e;"max"==a?c(f.root):"min"==a?b(f.root):d(f.root);return e};f.delNode=function(a){function c(g,h,l){if(null!=g)if(g.data==a){if(null==h)b(f.root.left,f.root.right),f.root=null!=f.root.right?f.root.right:null!=f.root.left?f.root.left:null;else{b(g.left,g.right);var k=null;null!=g.right?k=g.right:null!=g.left&&(k=g.left);"left"==l?h.left=k:"right"==l&&(h.right=k)}d=f.root;e=!0}else g.data<a?c(g.right,g,"right"):g.data>a&&c(g.left,g,"left")}function b(a,b){if(null!=b&&null!=a)for(;;)if(null==b.left){b.left=a;break}}var d=f.root,e=!1;c(f.root,null,null);return e?d:!1}}}});Algorithm.$package(function(h){h.search={seqsearch:function(f,a){for(var c=0;c<f.length;c++)if(f[c]==a)return c;return!1},binSearch:function(f,a){for(var c=!1,b=f.length-1,d=0;d<=b;){var e=parseInt((b+d)/2);if(f[e]==a){c=e;break}else f[e]>a?b=e-1:f[e]<a&&(d=e+1)}return c}}});