-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04bfc4e
commit 98fe0d4
Showing
7 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"imports": { | ||
"@std/data-structures": "jsr:@std/data-structures@^1.0.4" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { BinaryHeap, descend } from '@std/data-structures'; | ||
|
||
const maxHeap = new BinaryHeap<number>(descend); | ||
|
||
// 元素入堆積 | ||
maxHeap.push(1, 3, 6, 5, 9, 8, 15); | ||
|
||
// 取得堆積頂元素 | ||
console.log(maxHeap.peek()); // 15 | ||
|
||
// 頂元素出堆積 | ||
console.log(maxHeap.pop()); // 15 | ||
console.log(maxHeap.pop()); // 9 | ||
console.log(maxHeap.pop()); // 8 | ||
|
||
// 取得堆積大小 | ||
console.log(maxHeap.length); // 4 | ||
|
||
// 判斷堆積是否為空 | ||
console.log(maxHeap.isEmpty()); // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { BinaryHeap, ascend } from '@std/data-structures'; | ||
|
||
const minHeap = new BinaryHeap<number>(ascend); | ||
|
||
// 元素入堆積 | ||
minHeap.push(1, 3, 6, 5, 9, 8, 15); | ||
|
||
// 取得堆積頂元素 | ||
console.log(minHeap.peek()); // 1 | ||
|
||
// 頂元素出堆積 | ||
console.log(minHeap.pop()); // 1 | ||
console.log(minHeap.pop()); // 3 | ||
console.log(minHeap.pop()); // 5 | ||
|
||
// 取得堆積大小 | ||
console.log(minHeap.length); // 4 | ||
|
||
// 判斷堆積是否為空 | ||
console.log(minHeap.isEmpty()); // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters