forked from Suryakant-Bharti/Important-Java-Concepts
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDUGraph.kt
More file actions
30 lines (22 loc) Β· 668 Bytes
/
DUGraph.kt
File metadata and controls
30 lines (22 loc) Β· 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package algo.graphs.directed.unweighted
import algo.datastructures.Queue
import algo.graphs.Graph
class DUGraph(public override val V: Int): Graph {
override var E: Int = 0
private val adj: Array<Queue<Int>> = Array(V) { Queue<Int>() }
private val indegree: IntArray = IntArray(V)
public fun addEdge(from: Int, to: Int) {
adj[from].add(to)
indegree[to]++
E++
}
public override fun adjacentVertices(from: Int): Collection<Int> {
return adj[from]
}
public fun outdegree(from: Int): Int {
return adj[from].size
}
public fun indegree(v: Int): Int {
return indegree[v]
}
}