A screenshot can be found here
Images
- https://media.cheggcdn.com/media/b9d/b9d19b2f-e7e9-43ed-80a8-f5cc4cbe8654/phplW5wFH.png
- https://media.cheggcdn.com/media/027/027c0228-323d-43ee-b9dd-a766b1548eb0/phpY2i471.png
- https://media.cheggcdn.com/media/f14/f1469362-2e60-44b8-9e91-db999d3002ed/phpvzNLiP.png
The question seems to have changed though
You get a list of vertices V ([x, y], [a, z], [x, a]) where a, x, y, z are nodes Where Vn represents a line connecting say x and z The goal is to:
- Find all connections
- All lonely nodes
- Have two cursors
- Have a list of connections
- The first walking through the list:
- Pick an element, if it doesnt exist already in the connections list (and the second item also doesnt), create a new set in that list
- If one of the elements exist in the connections list, simply add the other to that set
- Looking up if the node exists in a vertice (if its connected): Sort the array first, then compare Max() and node
- Use a generator (or iterator) to generate the node space from the number of nodes
Updated to check for the existence of a node in a connected vertice in one pass