dbl-linked-list-ds
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -33,3 +33,3 @@ { | ||
}, | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"devDependencies": { | ||
@@ -36,0 +36,0 @@ "@types/mocha": "^5.2.5", |
@@ -7,5 +7,7 @@ import { LinkedListNode } from './LinkedListNode'; | ||
private tailN; | ||
constructor(...values: T[]); | ||
add(val: T): LinkedListNode<T>; | ||
forEach<C>(f: ((value: LinkedListNode<T>) => void), ctx?: C): void; | ||
head(): Node<T>; | ||
pop(): T | undefined; | ||
remove(n: LinkedListNode<T>): void; | ||
@@ -12,0 +14,0 @@ tail(): Node<T>; |
@@ -5,6 +5,9 @@ "use strict"; | ||
class LinkedList { | ||
constructor() { | ||
constructor(...values) { | ||
this.length = 0; | ||
this.headN = undefined; | ||
this.tailN = undefined; | ||
for (const i of values) { | ||
this.add(i); | ||
} | ||
} | ||
@@ -37,2 +40,9 @@ add(val) { | ||
} | ||
pop() { | ||
const h = this.head(); | ||
if (h !== undefined) { | ||
this.remove(h); | ||
return h.value; | ||
} | ||
} | ||
remove(n) { | ||
@@ -39,0 +49,0 @@ if (n.left !== undefined && n.right !== undefined) { |
186103
133