From 97a58430a248b9ea89a7da0120cfceb0e6b11af5 Mon Sep 17 00:00:00 2001 From: Dobromir Ivanov Date: Wed, 7 Nov 2018 15:06:45 +0200 Subject: A (naive) golang implementation of a JavaScript lexer. (#18) Not that comments single line or multi line are not parsed. Numbers are parsed in the most naive way possible so don't expect miracles. --- homework/45180/hw1.html | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 homework/45180/hw1.html (limited to 'homework/45180/hw1.html') diff --git a/homework/45180/hw1.html b/homework/45180/hw1.html new file mode 100644 index 0000000..74c7f4b --- /dev/null +++ b/homework/45180/hw1.html @@ -0,0 +1,75 @@ + + + + + + + +
+export default class Queue {
+    constructor() {
+        this._firstNode = null;
+        this._lastNode = null;
+    }
+
+    dequeue() {
+        if (!this._firstNode) {
+            return this._firstNode;
+        }
+
+        const payload = this._firstNode.payload;
+
+        this._firstNode = this._firstNode.next;
+
+        return payload;
+    }
+
+    enqueue(item) {
+        const newNode = {
+            payload: item,
+            next: null
+        };
+
+        if (this._firstNode === null) {
+            this._firstNode = newNode;
+            this._lastNode = newNode;
+
+        } else {
+            this._lastNode.next = newNode;
+            this._lastNode = newNode;
+        }
+    }
+
+    clear() {
+        this._firstNode = null;
+        this._lastNode = null;
+    }
+
+    top() {
+        if (!this._firstNode) {
+            return this._firstNode;
+        }
+
+        return this._firstNode.payload;
+    }
+
+    isEmpty() {
+        return !this._firstNode;
+    }
+}
\ No newline at end of file -- cgit v1.3.1-26-gb76a