Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top