davecom / SwiftGraph

A Graph Data Structure in Pure Swift
Apache License 2.0
758 stars 80 forks source link

Running BFS/DFS and returning the names associated with edges #83

Closed Erice224 closed 2 years ago

Erice224 commented 2 years ago

Hello, I have string vertices in a weighted undirected graph. I created edges doing AddEdge(from: "name1", to: "name2", weight: xx). When i run BFS/DFS and print the list of edges i get back, the u and v fields are ints. I assume this is the index of the vertices. Is there a way to get the string name associated with the vertex at this point? Thanks.

davecom commented 2 years ago

Hi Eric,

You can call vertexAtIndex() to convert from an index to a vertex.

David

Erice224 commented 2 years ago

Awesome Thank you! Really appreciate the work that went into this tool :D