/*! * linked-list-adt - Linked List ADT for browser and nodejs * @version v0.2.1 - Sat Aug 23 2014 * @link https://github.com/pasangsherpa/linked-list-adt * @author Pasang Sherpa (https://github.com/pasangsherpa) * @license MIT */ !function(){"use strict";var n=function(){function n(n){this.element=n||null,this.next=null}function e(e){var t=new n(e),r=null;if(null===s)s=t;else{for(r=s;null!==r.next;)r=r.next;r.next=t}d++}function t(n){var e=i(n>=0?n:d-1);return s="undefined"!=typeof n?r(n,s):r(d-1,s),d--,e.element}function r(n,e){if(null===e)throw new Error("removeAt(): No such element found.");return 0===n?e.next:(e.next=r(n-1,e.next),e)}function u(){if(f())throw new Error("first(): List is empty.");return s.element}function i(n){if(0>n||n>d||null===s)return null;for(var e=s,t=0;n>t;t++)e=e.next;return e}function o(n){return i(n).element}function f(){return 0===d}function l(){return d}function c(){function n(){return d>u}function e(){if(!n())throw new Error("next(): No such element.");u||(r=s),t=r;var e=r.element;return r=r.next,u++,e}var t=null,r=null,u=0;return{hasNext:n,next:e}}var s=null,d=0;return{add:e,remove:t,first:u,get:o,isEmpty:f,size:l,iterator:new c}};"function"==typeof define&&define.amd?define(function(){return n}):"undefined"!=typeof module&&module.exports?module.exports=n:window.LinkedList=n}();