Skip to content

Commit 2f2c099

Browse files
author
root
committed
Updated kahn's algorithm
1 parent 9f3aa64 commit 2f2c099

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Graphs/KahnsAlgorithm.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export function KahnsAlgorithm(graph, n) {
1818
if (n === null || n === undefined) throw Error('Invalid n was given')
1919
const inDegree = Array(n).fill(0)
2020
const result = []
21-
for (const neigbhours of graph) {
22-
for (const neigbhour of neigbhours) {
23-
inDegree[neigbhour] += 1
21+
for (const neighbours of graph) {
22+
for (const neighbour of neighbours) {
23+
inDegree[neighbour] += 1
2424
}
2525
}
2626
const queue = new Queue()
@@ -33,10 +33,10 @@ export function KahnsAlgorithm(graph, n) {
3333
while (queue.length !== 0) {
3434
const node = queue.dequeue()
3535
result.push(node)
36-
for (const neigbhour of graph[node]) {
37-
inDegree[neigbhour] -= 1
38-
if (inDegree[neigbhour] == 0) {
39-
queue.enqueue(neigbhour)
36+
for (const neighbour of graph[node]) {
37+
inDegree[neighbour] -= 1
38+
if (inDegree[neighbour] == 0) {
39+
queue.enqueue(neighbour)
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)