【发布时间】:2021-10-27 14:02:47
【问题描述】:
对于下面的问题,我真的有点一头雾水。
我应该创建一个包含一组节点和边的图表。方法“add”应该检查边缘是重复还是反向重复。如果不是这种情况,则应将此新边添加到相应的集合中。因此,我需要在方法中创建 Edge 类的实例并执行 for 循环以检查条件是否满足。
我真的被困在这里,我希望你们中的一些人能给我一个提示:)
提前致谢 BR
class Graph {
constructor() {
this.nodes = new Set();
this.edges = new Set();
}
add(m,n){
const e = new Edge (m,n);
}
};
class Edge {
constructor(startpoint,endpoint) {
this.startpoint = startpoint;
this.endpoint = endpoint;
}
};
class Node {
constructor(nodeName) {
this.nodeName = nodeName
}
};
【问题讨论】:
标签: javascript oop instance