数据结构
堆和栈
堆和栈 🔗Queue 🔗 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import LinkedList from "./LinkedList"; class Queue { constructor() { this.linkedList = new LinkedList(); } isEmpty() { return !this.linkedList.head; } peek() { if (this.isEmpty()) return null; return this.linkedList.head.value; } enqueue(value) { this.linkedList.prepend(value); } dequeue() { return this.linkedList.deleteHead();
阅读全文
200 字