Good day. Help solve the problem, well, or in what place to dig? (Google did not help)

There is a list of faces: [1, 2, 3, 4, 5, 6]

There is a list of vertices from the faces: [(2, 6), (3, 7), (8, 2), (8, 3), (6, 9), (7, 9)]
(where the index of a pair of vertices corresponds to the index of the face)

The task: to sort the faces by the condition of common vertices. If the face has a common vertex with the checked one, add it to the list. At the same time observing the sequence.

For example:

faces (2, 6) and (6, 9) have a common vertex 6, in the list (1)

faces (6, 9) and (7, 9) have a common vertex 9, in the list (1, 5)

faces (7, 9) and (3, 7) have a common vertex 7, to the list (1, 5, 6)

etc.

output: [1, 5, 6, 2, 4, 3]

How to express such a check in code?

    1 answer 1

    Faces and peaks, you say? and as for me, it is a simple graph, only in an unusual interpretation - the edges are numbered and named faces, and the nodes are called vertices and are determined by the set of edges leaving the node (and what is remarkable - all the nodes are exclusively dual).

    So change the terminology and use the usual algorithms to bypass the undirected graph.

    • In fact, it could be sticks / pebbles, that's not the point. Took from the original vertex and edge, connected with 3D. Thanks for the direction, I will look in DFS. - KSN
    • upd: got used to the English terminology of vertex / face / edge and confused them when translating. I look at the edge, call the edge, in the place of the edge, facepalm. - KSN