shapefile/list.js
raw| 1 | module.exports = function() { |
| 2 | var head = null, |
| 3 | tail = null; |
| 4 | return { |
| 5 | empty: function() { |
| 6 | return !tail; |
| 7 | }, |
| 8 | push: function(value) { |
| 9 | var node = {value: value, next: null}; |
| 10 | if (tail) tail = tail.next = node; |
| 11 | else head = tail = node; |
| 12 | return value; |
| 13 | }, |
| 14 | pop: function() { |
| 15 | if (!head) return null; |
| 16 | var value = head.value; |
| 17 | if (head === tail) head = tail = null; |
| 18 | else head = head.next; |
| 19 | return value; |
| 20 | } |
| 21 | }; |
| 22 | }; |