Question: How this code will look like if is written in C++? // Example graph 1 val z = Graph(1~>2, 2~>3, 2~>4, 3~>4, 5~>4) // Example

How this code will look like if is written in C++?

// Example graph 1 val z = Graph(1~>2, 2~>3, 2~>4, 3~>4, 5~>4) // Example graph 2 val z1 = Graph(1~>2, 2~>3, 2~>4, 3~>4, 4~>6, 6~>7, 5~>4) def getAllPaths(g: z1.NodeT, paths: List[z1.NodeT]): List[Any] = { val directs = g.diSuccessors.toList if (directs.length == 0) { // No more direct successor left, return the array itself paths } else if (directs.length == 1) { // Node with single direction, simply returns itself if (paths.length == 0) { // appends g itself and its direct successor for the first iteration getAllPaths(directs(0), paths :+ g :+ directs(0)) } else { // Appends only the direct successor getAllPaths(directs(0), paths :+ directs(0)) } } else { directs.map(d => { getAllPaths(d, paths :+ d) }) } } val accum = List[z1.NodeT]() println(getAllPaths(z1.get(1), accum)) // Results in: List(List(1, 2, 3, 4, 6, 7), List(1, 2, 4, 6, 7))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!