I have code in scala :
val graph = new Array [Set[Int]] (n)
def addedge(i:Int,j:Int)
{
graph(i)+=j
}
What does graph(i)+=j mean?
Can anybody translate it in any other languages like c, c++ or java?
graph is an Array, just like in C or Java. graph(i) means "access the ith element of graph". Each element in graph is a Set of Ints. The += method on Set adds an item to the Set. So graph(i) += j adds the number j into the Set stored at index i in graph.
Trying things out in the REPL shows the behavior:
scala> val graph = Array(Set(1,2), Set(2,3), Set(1))
graph: Array[scala.collection.immutable.Set[Int]] = Array(Set(1, 2), Set(2, 3), Set(1))
scala> graph(1) += 4
scala> graph
res0: Array[scala.collection.immutable.Set[Int]] = Array(Set(1, 2), Set(2, 3, 4), Set(1))