<!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>