I wish to have a datastructure(array or slice) to look like this :
[[a b c d e][f g h i j] [k l m n o] [p q r s t] [u v w x y]]
such that a is the distance between node from "A" to "A" . (which shall be 0) b is the distance between node from "A" to "B" . c is the distance between node from "A" to "C" .
f is the distance between node from "B" to "A" . g is the distance between node from "B" to "B" . (which shall be 0) h is the distance between node from "B" to "C" .
Now I have created a slice like :
var shortestPathSLice = make([][]int, 5)
to store this 2D data.
In my for loop within a function, I am trying to fill this slice dynamically as follows :
shortestPathSLice = append(shortestPathSLice[0][index], lowEstimate[0])
where lowestimate[0] is value of the smallest distances between two nodes.
However, I get an error with this : first argument to append must be slice; have int
Can anyone tell me how can I dynamically append values in EACH ELEMENT in my slice ?
**CODE **
var shortestPathSLice = make([][]int, 5)
for index := 0; index < len(t.Location_ids); index++ {
lowEstimate := make([]int, len(priceestimatestruct.Prices))
for i := 0; i < len(priceestimatestruct.Prices); i++ {
lowEstimate[i] = priceestimatestruct.Prices[i].LowEstimate
}
sort.Ints(lowEstimate)
fmt.Println("LowEstimate array : ", lowEstimate)
shortestPathSLice[0] = make([]int, len(lowEstimate))
shortestPathSLice[0][index] = lowEstimate[0]
}