Skip to content

Commit e050e09

Browse files
committed
Style: format TopologicalSort.java using clang-format
1 parent 58f53b2 commit e050e09

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ public class TopologicalSort {
2020
public static void main(String[] args) {
2121
int v = 6;
2222
ArrayList<ArrayList<Integer>> adjList = new ArrayList<>();
23-
for(int i=0; i<v; i++){
23+
for (int i = 0; i < v; i++) {
2424
adjList.add(new ArrayList<>());
2525
}
2626

27-
//sample DAG edges
27+
// sample DAG edges
2828
adjList.get(5).add(2);
2929
adjList.get(5).add(0);
3030
adjList.get(4).add(0);
3131
adjList.get(4).add(1);
3232
adjList.get(2).add(3);
3333
adjList.get(3).add(1);
3434

35-
topoSort(v,adjList);
35+
topoSort(v, adjList);
3636
}
3737

3838
/**
@@ -43,20 +43,19 @@ public static void main(String[] args) {
4343
* @param adjList adjacency list representing the graph
4444
*/
4545

46-
47-
public static void topoSort (int v, ArrayList<ArrayList<Integer>> adjList){
48-
boolean [] visited = new boolean[v];
49-
Stack <Integer> stack = new Stack<>();
46+
public static void topoSort(int v, ArrayList<ArrayList<Integer>> adjList) {
47+
boolean[] visited = new boolean[v];
48+
Stack<Integer> stack = new Stack<>();
5049

5150
for (int i = 0; i < v; i++) {
52-
if(!visited[i]){
53-
topoSortUtil(i,visited,stack,adjList);
51+
if (!visited[i]) {
52+
topoSortUtil(i, visited, stack, adjList);
5453
}
5554
}
5655

5756
System.out.println("Topological Sort:");
58-
while (!stack.isEmpty()){
59-
System.out.print(stack.pop()+" ");
57+
while (!stack.isEmpty()) {
58+
System.out.print(stack.pop() + " ");
6059
}
6160
System.out.println();
6261
}
@@ -72,12 +71,12 @@ public static void topoSort (int v, ArrayList<ArrayList<Integer>> adjList){
7271
*
7372
*/
7473

75-
public static void topoSortUtil(int node, boolean[] visited, Stack<Integer> stack, ArrayList<ArrayList<Integer>> adjList){
74+
public static void topoSortUtil(int node, boolean[] visited, Stack<Integer> stack, ArrayList<ArrayList<Integer>> adjList) {
7675
visited[node] = true;
7776

78-
for(int neighbour : adjList.get(node)){
79-
if(!visited[neighbour]){
80-
topoSortUtil(neighbour,visited,stack,adjList);
77+
for (int neighbour : adjList.get(node)) {
78+
if (!visited[neighbour]) {
79+
topoSortUtil(neighbour, visited, stack, adjList);
8180
}
8281
}
8382
stack.push(node); // add to stack after visiting all edges

0 commit comments

Comments
 (0)