()
| 46 | } |
| 47 | |
| 48 | pop() { |
| 49 | let cur = this.head; |
| 50 | |
| 51 | // only one or no item exists |
| 52 | if (!cur) return null; |
| 53 | if (!cur.next) { |
| 54 | this.head = null; |
| 55 | return cur; |
| 56 | } |
| 57 | // move till the 2nd last |
| 58 | while (cur.next.next) |
| 59 | cur = cur.next; |
| 60 | |
| 61 | let last = this.tail; |
| 62 | this.tail = cur; |
| 63 | this.tail.next = null; |
| 64 | return last; |
| 65 | } |
| 66 | |
| 67 | popFirst() { |
| 68 | let first = this.head; |