UNPKG

another-linked-list

Version:
2 lines 2.6 kB
define("linked-list.amd",[],(()=>(()=>{"use strict";var t={462:(t,e,n)=>{function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}n.d(e,{default:()=>l});var a=function(){function t(e,n){void 0===n&&(n=null),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.value=e,this.next=n}var e,n;return e=t,(n=[{key:"toString",value:function(t){return t?t(this.value):""+this.value}}])&&i(e.prototype,n),t}();function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}const l=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.head=null,this.tail=null}var e,n;return e=t,(n=[{key:"prepend",value:function(t){var e=new a(t,this.head);return this.head=e,this.tail||(this.tail=e),this}},{key:"append",value:function(t){var e=new a(t);return this.head?(this.tail.next=e,this.tail=e,this):(this.head=e,this.tail=e,this)}},{key:"delete",value:function(t){if(!this.head)return null;for(var e=null;this.head&&this.head.value===t;)e=this.head,this.head=this.head.next;var n=this.head;if(null!==n)for(;n.next;)n.next.value===t?(e=n.next,n.next=n.next.next):n=n.next;return this.tail.value===t&&(this.tail=n),e}},{key:"deleteTail",value:function(){var t=this.tail;if(this.head===this.tail)return this.head=null,this.tail=null,t;for(var e=this.head;e.next;)e.next.next?e=e.next:e.next=null;return this.tail=e,t}},{key:"deleteHead",value:function(){if(!this.head)return null;var t=this.head;return this.head.next?this.head=this.head.next:(this.head=null,this.tail=null),t}},{key:"find",value:function(t){var e=t.value,n=void 0===e?void 0:e,i=t.callback,a=void 0===i?void 0:i;if(!this.head)return null;for(var r=this.head;r;){if(a&&a(r.value))return r;if(void 0!==n&&r.value===n)return r;r=r.next}return null}},{key:"toArray",value:function(){for(var t=[],e=this.head;e;)t.push(e),e=e.next;return t}},{key:"toString",value:function(t){return this.toArray().map((function(e){return e.toString(t)})).toString()}}])&&r(e.prototype,n),t}()}},e={};function n(i){if(e[i])return e[i].exports;var a=e[i]={exports:{}};return t[i](a,a.exports,n),a.exports}return n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n(462)})().default)); //# sourceMappingURL=linked-list.amd.min.js.map