有向图-边的表示
有向图需要用到权的概念,即是两个顶点之间的权重,在现实生活中,可以用来表示两个顶点之间的距离,也可以表示两个顶点之间的交通费用。
代码实现
class Edge {
constructor(a, b, w) {
this.a = a;
this.b = b;
this.weight = w;
}
v() {
return this.a;
}
w() {
return this.b;
}
weight() {
return this.weight;
}
other(x) {
if (x !== this.a || x !== this.b) {
throw new Error('Not valid vertex');
}
return x !== this.a ? this.b : this.a;
}
}
module.exports = Edge;
FEATURED TAGS
前端开发
H5
JavaScript
设计模式
browser
jQuery
源码分析
生活
leetcode
Array
Stack
Queue
Linked List
剑指offer
Binary Search Tree
Binary Tree
Breadth-First Search
Depth-First Search
String
Set
Binary Search
Sliding Window
Backtracking
Dynamic Programming
Two Pointers
Union Find
Sort
Bit Operation
Recursion
Map
Graph
Search
Hash
LinkedList
复盘
QuickSort
Trie
Design
MinHeap
Traverse
Min Heap
Node.js
BackEnd
SQL
MySQL
Design Patterns
Network
计算机网络
Python
SVG