Java: how to represent graphs?

前端 未结 12 1471
感动是毒
感动是毒 2020-12-02 12:17

I\'m implementing some algorithms to teach myself about graphs and how to work with them. What would you recommend is the best way to do that in Java? I was thinking somethi

12条回答
  •  天命终不由人
    2020-12-02 12:43

    class Vertex {
        private String name;
        private int score; // for path algos
        private boolean visited; // for path algos
        List connections;
    }
    
    class Edge {
        private String vertex1Name; // same as Vertex.name
        private String vertex2Name;
        private int length;
    }
    
    class Graph {
        private List edges;
    }
    

提交回复
热议问题