Skip to content

Commit

Permalink
225th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Oct 17, 2024
1 parent 05d06b9 commit 3a8cb0d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,12 @@ $ pnpm bench twoSum.bench.ts
- 雜湊表 (Hash Table)
- 堆積 (Heap)
- 樹 (Tree)
- 二元樹 (Binary Tree)
- 二元搜尋樹 (Binary Search Tree)
- [圖 (Graph)](./algorithms/graph/README.md)
- 字典樹 (Trie)
- 排序 (Sorting)
- 冒泡排序 (Bubble Sort)
- 選擇排序 (Selection Sort)
- 插入排序 (Insertion Sort)
- 合併排序 (Merge Sort)
- 快速排序 (Quick Sort)
- 堆積排序 (Heap Sort)
- 搜尋 (Searching)
- [二分搜尋 (Binary Search)](./algorithms/searching/README.md)
- 動態規劃 (Dynamic Programming)
- [0-1 背包問題 (0-1 Knapsack Problem)](./algorithms/dynamic-programming/README.md#0-1-背包問題-0-1-knapsack-problem)
- 完全背包問題 (Unbounded Knapsack Problem)
- 多維背包問題 (Multidimensional Knapsack Problem)
- [搜尋 (Searching)](./algorithms/searching/README.md)
- [動態規劃 (Dynamic Programming)](./algorithms/dynamic-programming/README.md)
- 貪婪 (Greedy)
- 分數背包問題 (Fractional Knapsack Problem)
- 回溯 (Backtracking)
- 分治 (Divide and Conquer)
- 位元操作 (Bit Manipulation)
Expand Down
2 changes: 1 addition & 1 deletion algorithms/dynamic-programming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const capacity = 4;
console.log(knapsack(weights, values, capacity)); // 20
```

## 完全背包問題 (Unbounded Knapsack Problem)
## 無界背包問題 (Unbounded Knapsack Problem)

遞推公式:

Expand Down
Empty file added algorithms/queue/Queue.ts
Empty file.
69 changes: 69 additions & 0 deletions algorithms/queue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 佇列 (Queue)

以先進先出 (First In First Out,FIFO) 為原則。

- [`Queue.ts`](./Queue.ts)

```ts
class Queue<T> {
private items: T[] = [];

// 加入元素到佇列的尾端
enqueue(item: T): void {
this.items.push(item);
}

// 從佇列的頭部移除元素
dequeue(): T | undefined {
return this.items.shift();
}

// 查看佇列的第一個元素(不移除)
peek(): T | undefined {
return this.items[0];
}

// 檢查佇列是否為空
isEmpty(): boolean {
return this.items.length === 0;
}

// 取得佇列的長度
size(): number {
return this.items.length;
}

// 清空佇列
clear(): void {
this.items = [];
}
}
```

```ts
const queue = new Queue<number>();

queue.enqueue(10);
queue.enqueue(20);
queue.enqueue(30);

console.log(queue.peek()); // 10
console.log(queue.dequeue()); // 10
console.log(queue.size()); // 2
console.log(queue.isEmpty()); // false

queue.clear();
console.log(queue.isEmpty()); // true
```

## 雙向佇列 (Double-ended Queue)

## 優先佇列 (Priority Queue)

## 雙向優先佇列 (Double Priority Queue)

## 有界佇列 (Bounded Queue)

### 圓形佇列 (Circular Queue) / 環形緩衝區 (Circular Buffer)

### 尾部丟棄 (Tail Drop)

0 comments on commit 3a8cb0d

Please sign in to comment.