-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vertex class for javascript and typescript (#370)
* add vertex class for javascript and typescript * update the adjacencyList * update the graph_adjacency_list file * update the implicit type --------- Co-authored-by: steak-zhuo <zhuoqinyue@gmail.com>
- Loading branch information
1 parent
04b0fb7
commit b89ea3e
Showing
4 changed files
with
172 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* File: Vertex.ts | ||
* 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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* File: Vertex.ts | ||
* Created Time: 2023-02-15 | ||
* Author: Zhuo Qinyue (1403450829@qq.com) | ||
*/ | ||
|
||
|
||
/* 顶点类 */ | ||
class Vertex { | ||
val: number; | ||
constructor(val: number) { | ||
this.val = val; | ||
} | ||
|
||
/* 输入值列表 vals ,返回顶点列表 vets */ | ||
public static valsToVets(vals: number[]): Vertex[] { | ||
const vets: Vertex[] = []; | ||
for (let i = 0; i < vals.length; i++) { | ||
vets[i] = new Vertex(vals[i]); | ||
} | ||
return vets; | ||
} | ||
|
||
/* 输入顶点列表 vets ,返回值列表 vals */ | ||
public static vetsToVals(vets: Vertex[]): number[] { | ||
const vals: number[] = []; | ||
for (const vet of vets) { | ||
vals.push(vet.val); | ||
} | ||
return vals; | ||
} | ||
} | ||
|
||
export { Vertex }; |