ログ

見る価値ありません

2021-06-01から1ヶ月間の記事一覧

JavaScriptで優先度付きキュー(二分ヒープ)

class PriorityQueue { constructor(comp) { this.heap = []; this.compare = comp; } isEmpty() { return this.heap.length == 0; } push(x) { this._upHeap(this.heap.push(x) - 1); } pop() { if(this.isEmpty()) { return undefined; } this._heapSwap(0…

JavaScriptで償却定数時間キュー

class Queue { constructor() { this.front = []; this.back = []; } isEmpty() { return this.front.length == 0 && this.back.length == 0; } push(x) { this.back.push(x); } pop() { if(this.isEmpty()) { return undefined; } if(this.front.length == …