Skip to content

Commit 11ba0e3

Browse files
Format Java files with clang-format
1 parent 608fe18 commit 11ba0e3

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/main/java/com/thealgorithms/graph/TopologicalSort.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class TopologicalSort {
2121
* manipulating the graph
2222
*/
2323
public static class Graph {
24-
private final int n; // Number of nodes
25-
private final List<List<Integer>> adj; // Adjacency list representation
24+
private final int n; // Number of nodes
25+
private final List<List<Integer>> adj; // Adjacency list representation
2626

2727
/**
2828
* Constructor for the Graph class
@@ -71,8 +71,7 @@ public int getNumNodes() {
7171
* @param stack Stack containing the vertices for topological sorting
7272
* @return true if cycle is detected, false otherwise
7373
*/
74-
private static boolean dfs(int v, boolean[] visited, boolean[] recStack,
75-
List<List<Integer>> graph, Stack<Integer> stack) {
74+
private static boolean dfs(int v, boolean[] visited, boolean[] recStack, List<List<Integer>> graph, Stack<Integer> stack) {
7675
visited[v] = true;
7776
recStack[v] = true;
7877

@@ -120,5 +119,4 @@ public static List<Integer> sort(Graph g) {
120119

121120
return ans;
122121
}
123-
124-
}
122+
}

src/test/java/com/thealgorithms/graph/TopologicalSortTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.thealgorithms.graph;
22

3-
import org.junit.jupiter.api.Test;
4-
import org.junit.jupiter.api.DisplayName;
53
import static org.junit.jupiter.api.Assertions.*;
64

75
import java.util.Arrays;
86
import java.util.List;
7+
import org.junit.jupiter.api.DisplayName;
8+
import org.junit.jupiter.api.Test;
99

1010
/**
1111
* Test class for TopologicalSort
@@ -326,17 +326,12 @@ void testCycleDetection() {
326326
TopologicalSort.Graph graph = new TopologicalSort.Graph(3);
327327
graph.addEdge(0, 1);
328328
graph.addEdge(1, 2);
329-
graph.addEdge(2, 0); // Creates a cycle: 0 -> 1 -> 2 -> 0
329+
graph.addEdge(2, 0); // Creates a cycle: 0 -> 1 -> 2 -> 0
330330

331331
// With the fixed code, this should now throw an exception
332-
IllegalArgumentException exception = assertThrows(
333-
IllegalArgumentException.class,
334-
() -> TopologicalSort.sort(graph),
335-
"Topological sort should detect cycle and throw IllegalArgumentException"
336-
);
332+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> TopologicalSort.sort(graph), "Topological sort should detect cycle and throw IllegalArgumentException");
337333

338334
// Verify the exception message
339335
assertEquals("cycle detected in graph", exception.getMessage());
340336
}
341-
342-
}
337+
}

0 commit comments

Comments
 (0)