Skip to content

Commit

Permalink
feat: add main
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Apr 19, 2024
1 parent d8c5a89 commit 39fe709
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 40 deletions.
76 changes: 39 additions & 37 deletions codes/typescript/chapter_graph/graph_adjacency_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,46 +92,48 @@ class GraphAdjList {
}

/* Driver Code */
/* 初始化无向图 */
const v0 = new Vertex(1),
v1 = new Vertex(3),
v2 = new Vertex(2),
v3 = new Vertex(5),
v4 = new Vertex(4);
const edges = [
[v0, v1],
[v1, v2],
[v2, v3],
[v0, v3],
[v2, v4],
[v3, v4],
];
const graph = new GraphAdjList(edges);
console.log('\n初始化后,图为');
graph.print();
if (import.meta.url === new URL('file://' + process.argv[1]).href) {
/* 初始化无向图 */
const v0 = new Vertex(1),
v1 = new Vertex(3),
v2 = new Vertex(2),
v3 = new Vertex(5),
v4 = new Vertex(4);
const edges = [
[v0, v1],
[v1, v2],
[v2, v3],
[v0, v3],
[v2, v4],
[v3, v4],
];
const graph = new GraphAdjList(edges);
console.log('\n初始化后,图为');
graph.print();

/* 添加边 */
// 顶点 1, 2 即 v0, v2
graph.addEdge(v0, v2);
console.log('\n添加边 1-2 后,图为');
graph.print();
/* 添加边 */
// 顶点 1, 2 即 v0, v2
graph.addEdge(v0, v2);
console.log('\n添加边 1-2 后,图为');
graph.print();

/* 删除边 */
// 顶点 1, 3 即 v0, v1
graph.removeEdge(v0, v1);
console.log('\n删除边 1-3 后,图为');
graph.print();
/* 删除边 */
// 顶点 1, 3 即 v0, v1
graph.removeEdge(v0, v1);
console.log('\n删除边 1-3 后,图为');
graph.print();

/* 添加顶点 */
const v5 = new Vertex(6);
graph.addVertex(v5);
console.log('\n添加顶点 6 后,图为');
graph.print();
/* 添加顶点 */
const v5 = new Vertex(6);
graph.addVertex(v5);
console.log('\n添加顶点 6 后,图为');
graph.print();

/* 删除顶点 */
// 顶点 3 即 v1
graph.removeVertex(v1);
console.log('\n删除顶点 3 后,图为');
graph.print();
/* 删除顶点 */
// 顶点 3 即 v1
graph.removeVertex(v1);
console.log('\n删除顶点 3 后,图为');
graph.print();
}

export { GraphAdjList };
4 changes: 2 additions & 2 deletions codes/typescript/chapter_heap/my_heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MaxHeap {
}

/* Driver Code */

if (import.meta.url === new URL('file://' + process.argv[1]).href) {
/* 初始化大顶堆 */
const maxHeap = new MaxHeap([9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2]);
console.log('\n输入列表并建堆后');
Expand Down Expand Up @@ -150,6 +150,6 @@ class MaxHeap {
/* 判断堆是否为空 */
const isEmpty = maxHeap.isEmpty();
console.log(`\n堆是否为空 ${isEmpty}`);

}

export { MaxHeap };
16 changes: 16 additions & 0 deletions codes/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codes/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"check": "tsc"
},
"devDependencies": {
"@types/node": "^20.12.7",
"tsx": "^4.7.2",
"typescript": "^5.4.5"
}
Expand Down
2 changes: 1 addition & 1 deletion codes/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"moduleResolution": "node",
"paths": {},
"resolveJsonModule": true,
"types": [],
"types": ["@types/node"],

"noEmit": true,

Expand Down

0 comments on commit 39fe709

Please sign in to comment.