数据结构190-添加顶点边代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function Graph(){
            this.vertexes=[] //顶点
            this.edges=new Dictionay() //边

            Graph.prototype.addVertexts=function(v){
                this.vertexes.push(v)
                this.edges.set(v,[])
            }
            Graph.prototype.addEdge=function(v1,v2){
                this.edges.get(v1).push(v2)
                this.edges.get(v1).push(v1)
            }
        }
    </script>
</body>
</html>

posted @ 2022-12-22 15:29  前端导师歌谣  阅读(31)  评论(0)    收藏  举报