How to write this code?

I have .csv file. Content of file like as follow:

A,B

B,C

A,F

F,G

G,H

B,D

each row has 2 vertices and and edge should add between them. my csv file have 100 row.

I know how to read csv file and how to add vertices for the first time but if vertex repeates,how should I know, I had it before and how to find it to add edge:(

How to write this code to get this output?

有帮助吗?

解决方案

To discard repeated vertexes you could put your vertexes to LinkedHashMap and in your code check if vertex is in the map.

If you are building a graph then you could learn from the code for graphs in book "Algorithms" by Robert Sedgewick and Kevin Wayne.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top