Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: use internal queue definition in BFS#1228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletionsGraphs/BreadthFirstSearch.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
import Queue from '../Data-Structures/Queue/Queue'

/**
* Breadth-first search is an algorithm for traversing a graph.
*
Expand All@@ -12,11 +14,12 @@ export function breadthFirstSearch (graph, startingNode) {
const visited = new Set()

// queue contains the nodes to be explored in the future
const queue = [startingNode]
const queue = new Queue()
queue.enqueue(startingNode)

while (queue.length > 0) {
while (!queue.isEmpty()) {
// start with the queue's first node
const node = queue.shift()
const node = queue.dequeue()

if (!visited.has(node)) {
// mark the node as visited
Expand All@@ -25,7 +28,7 @@ export function breadthFirstSearch (graph, startingNode) {

// put all its neighbors into the queue
for (let i = 0; i < neighbors.length; i++) {
queue.push(neighbors[i])
queue.enqueue(neighbors[i])
}
}
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp