mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-14 02:10:37 +08:00
Translate all code to English (#1836)
* Review the EN heading format. * Fix pythontutor headings. * Fix pythontutor headings. * bug fixes * Fix headings in **/summary.md * Revisit the CN-to-EN translation for Python code using Claude-4.5 * Revisit the CN-to-EN translation for Java code using Claude-4.5 * Revisit the CN-to-EN translation for Cpp code using Claude-4.5. * Fix the dictionary. * Fix cpp code translation for the multipart strings. * Translate Go code to English. * Update workflows to test EN code. * Add EN translation for C. * Add EN translation for CSharp. * Add EN translation for Swift. * Trigger the CI check. * Revert. * Update en/hash_map.md * Add the EN version of Dart code. * Add the EN version of Kotlin code. * Add missing code files. * Add the EN version of JavaScript code. * Add the EN version of TypeScript code. * Fix the workflows. * Add the EN version of Ruby code. * Add the EN version of Rust code. * Update the CI check for the English version code. * Update Python CI check. * Fix cmakelists for en/C code. * Fix Ruby comments
This commit is contained in:
@@ -16,15 +16,15 @@ class GraphAdjMat:
|
||||
|
||||
def __init__(self, vertices: list[int], edges: list[list[int]]):
|
||||
"""Constructor"""
|
||||
# Vertex list, elements represent "vertex value", index represents "vertex index"
|
||||
# Vertex list, where the element represents the "vertex value" and the index represents the "vertex index"
|
||||
self.vertices: list[int] = []
|
||||
# Adjacency matrix, row and column indices correspond to "vertex index"
|
||||
# Adjacency matrix, where the row and column indices correspond to the "vertex index"
|
||||
self.adj_mat: list[list[int]] = []
|
||||
# Add vertex
|
||||
# Add vertices
|
||||
for val in vertices:
|
||||
self.add_vertex(val)
|
||||
# Add edge
|
||||
# Edges elements represent vertex indices
|
||||
# Add edges
|
||||
# Note that the edges elements represent vertex indices, i.e., corresponding to the vertices element indices
|
||||
for e in edges:
|
||||
self.add_edge(e[0], e[1])
|
||||
|
||||
@@ -35,7 +35,7 @@ class GraphAdjMat:
|
||||
def add_vertex(self, val: int):
|
||||
"""Add vertex"""
|
||||
n = self.size()
|
||||
# Add new vertex value to the vertex list
|
||||
# Add the value of the new vertex to the vertex list
|
||||
self.vertices.append(val)
|
||||
# Add a row to the adjacency matrix
|
||||
new_row = [0] * n
|
||||
@@ -48,27 +48,27 @@ class GraphAdjMat:
|
||||
"""Remove vertex"""
|
||||
if index >= self.size():
|
||||
raise IndexError()
|
||||
# Remove vertex at `index` from the vertex list
|
||||
# Remove the vertex at index from the vertex list
|
||||
self.vertices.pop(index)
|
||||
# Remove the row at `index` from the adjacency matrix
|
||||
# Remove the row at index from the adjacency matrix
|
||||
self.adj_mat.pop(index)
|
||||
# Remove the column at `index` from the adjacency matrix
|
||||
# Remove the column at index from the adjacency matrix
|
||||
for row in self.adj_mat:
|
||||
row.pop(index)
|
||||
|
||||
def add_edge(self, i: int, j: int):
|
||||
"""Add edge"""
|
||||
# Parameters i, j correspond to vertices element indices
|
||||
# Parameters i, j correspond to the vertices element indices
|
||||
# Handle index out of bounds and equality
|
||||
if i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:
|
||||
raise IndexError()
|
||||
# In an undirected graph, the adjacency matrix is symmetric about the main diagonal, i.e., satisfies (i, j) == (j, i)
|
||||
# In an undirected graph, the adjacency matrix is symmetric about the main diagonal, i.e., (i, j) == (j, i)
|
||||
self.adj_mat[i][j] = 1
|
||||
self.adj_mat[j][i] = 1
|
||||
|
||||
def remove_edge(self, i: int, j: int):
|
||||
"""Remove edge"""
|
||||
# Parameters i, j correspond to vertices element indices
|
||||
# Parameters i, j correspond to the vertices element indices
|
||||
# Handle index out of bounds and equality
|
||||
if i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:
|
||||
raise IndexError()
|
||||
@@ -85,7 +85,7 @@ class GraphAdjMat:
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
# Initialize undirected graph
|
||||
# Edges elements represent vertex indices
|
||||
# Note that the edges elements represent vertex indices, i.e., corresponding to the vertices element indices
|
||||
vertices = [1, 3, 2, 5, 4]
|
||||
edges = [[0, 1], [0, 3], [1, 2], [2, 3], [2, 4], [3, 4]]
|
||||
graph = GraphAdjMat(vertices, edges)
|
||||
@@ -93,13 +93,13 @@ if __name__ == "__main__":
|
||||
graph.print()
|
||||
|
||||
# Add edge
|
||||
# Indices of vertices 1, 2 are 0, 2 respectively
|
||||
# Vertices 1, 2 have indices 0, 2 respectively
|
||||
graph.add_edge(0, 2)
|
||||
print("\nAfter adding edge 1-2, the graph is")
|
||||
graph.print()
|
||||
|
||||
# Remove edge
|
||||
# Indices of vertices 1, 3 are 0, 1 respectively
|
||||
# Vertices 1, 3 have indices 0, 1 respectively
|
||||
graph.remove_edge(0, 1)
|
||||
print("\nAfter removing edge 1-3, the graph is")
|
||||
graph.print()
|
||||
@@ -110,7 +110,7 @@ if __name__ == "__main__":
|
||||
graph.print()
|
||||
|
||||
# Remove vertex
|
||||
# Index of vertex 3 is 1
|
||||
# Vertex 3 has index 1
|
||||
graph.remove_vertex(1)
|
||||
print("\nAfter removing vertex 3, the graph is")
|
||||
graph.print()
|
||||
|
||||
Reference in New Issue
Block a user