Currently translating weighted DAG to C code which is written in Go language and topologically sorted. Actually I missed a couple part of the code that is the code below sample. In topoSort function, I couldn't get what "visit" declaration is. Is it function declaration within another function ? Another part is that in main function that you'll see it below, couldn't get slicing processes with range keyword in loops. If you translate into C syntax roughly or briefly that would be great.
// topoSort()
func (g *graph) topoSort() []int {
result := make([]int, g.size())
marks := make([]bool, g.size())
resultIndex := g.size() - 1
var visit func(int)
visit = func(u int) {
for _, item := range g.adjList[u] {
if !marks[item.vertex] {
visit(item.vertex)
}
}
marks[u] = true
result[resultIndex] = u
resultIndex--
}
for u := range g.adjList {
if !marks[u] {
visit(u)
}
}
return result
}
// main()
i := 0
for rowIndex, row := range input {
for _, number := range row {
if rowIndex+1 >= len(input) {
g.addEdge(i, vertexesQuantity, number)
} else {
g.addEdge(i, i + rowIndex + 1, number)
g.addEdge(i, i + rowIndex + 2, number)
}
i++
}
}
What I have tried:
I made it and converted basic graph ( weighted DAG ) structure from that sample and there no issue about that. I just struggled with that two of them functions to convert to C code as I described above.