How to implement graph in core java?

前端 未结 3 1695
醉话见心
醉话见心 2021-01-19 06:44

I\'ve a directed unweighted graph. Number of nodes and all links between nodes are given. I tried to do the task with array of vectors but java doesn\'t support it. ArrayLis

相关标签:
3条回答
  • 2021-01-19 06:52

    An adjacency list such as Map<Node, List<Node>> or List<List<Node>> may be suitable.

    Addendum: In using Java Collections, it may be helpful to note that Map and List are interfaces that provide characteristic methods, while you may want to choose specific implementations based on the requirements of the algorithms you want to implement using your data structure.

    Addendum: There's a related example here.

    0 讨论(0)
  • 2021-01-19 06:56

    Too bad that you are asking for an implementation of a directed unweighted graph rather than for a straight-use. Otherwise, I will suggest you to use a readily-made framework for almost anything that relates to network/graph called JUNG2. You can use it either in GUI or in non-GUI mode. It will save you a lot of time tinkering. Following is its tutorial link:

    http://www.grotto-networking.com/JUNG/JUNG2-Tutorial.pdf

    0 讨论(0)
  • 2021-01-19 07:01

    You could use many collection data structures, in particular hash tables or sets, for your purpose. Java gives you a lot of collection generic containers (HashMap-s, ArrayList-s etc etc.). I'm not a Java expert, but searching for Java Collections give a big lot of results, e.g. this tutorial

    0 讨论(0)
提交回复
热议问题