Skip to content

Commit b8f1c7c

Browse files
committed
restore topo
1 parent ce74e63 commit b8f1c7c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

code_to_optimize/bubble_sort.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import sys
2+
13
def sorter(arr):
2-
print("codeflash stdout: Sorting list")
3-
# Use Python's built-in sort for much faster performance
4-
arr.sort()
5-
print(f"result: {arr}")
4+
sys.stdout.write("codeflash stdout: Sorting list\n") # Faster than print()
5+
arr.sort() # already optimal
6+
sys.stdout.write(f"result: {arr}\n") # Minimize print overhead
67
return arr

code_to_optimize/topological_sort.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ def addEdge(self, u, v):
1111

1212
def topologicalSortUtil(self, v, visited, stack):
1313
visited[v] = True
14+
1415
for i in self.graph[v]:
15-
if not visited[i]:
16+
if visited[i] == False:
1617
self.topologicalSortUtil(i, visited, stack)
17-
stack.append(v) # append to end for O(1) operation
18+
19+
stack.insert(0, v)
1820

1921
def topologicalSort(self):
2022
visited = [False] * self.V
2123
stack = []
24+
2225
for i in range(self.V):
23-
if not visited[i]:
26+
if visited[i] == False:
2427
self.topologicalSortUtil(i, visited, stack)
25-
stack.reverse() # correct order after all vertices are processed
28+
2629
return stack

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ formatter-cmds = [
240240
]
241241

242242

243+
[tool.pytest.ini_options]
244+
addopts = ["", "", "", "", ""]
243245
[build-system]
244246
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.2.0,<2.0.0"]
245247
build-backend = "poetry_dynamic_versioning.backend"

0 commit comments

Comments
 (0)