mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 23:56:28 +08:00
36 lines
691 B
JavaScript
36 lines
691 B
JavaScript
|
/**
|
||
|
* File: Vertex.js
|
||
|
* Created Time: 2023-02-15
|
||
|
* Author: Zhuo Qinyue (1403450829@qq.com)
|
||
|
*/
|
||
|
|
||
|
/* 頂點類別 */
|
||
|
class Vertex {
|
||
|
val;
|
||
|
constructor(val) {
|
||
|
this.val = val;
|
||
|
}
|
||
|
|
||
|
/* 輸入值串列 vals ,返回頂點串列 vets */
|
||
|
static valsToVets(vals) {
|
||
|
const vets = [];
|
||
|
for (let i = 0; i < vals.length; i++) {
|
||
|
vets[i] = new Vertex(vals[i]);
|
||
|
}
|
||
|
return vets;
|
||
|
}
|
||
|
|
||
|
/* 輸入頂點串列 vets ,返回值串列 vals */
|
||
|
static vetsToVals(vets) {
|
||
|
const vals = [];
|
||
|
for (const vet of vets) {
|
||
|
vals.push(vet.val);
|
||
|
}
|
||
|
return vals;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
Vertex,
|
||
|
};
|