mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 15:46:30 +08:00
e4a98bc9c5
* Update JavaScript and TypeScript codes * Rename JavaScript and TypeScript import folder to modules
36 lines
688 B
JavaScript
36 lines
688 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
|
|
};
|