Question: Question: Write a program in Java to implement the topological sorting algorithm. Assume that the vertices of the digraph are lowercase letters. The main() method

Question: Write a program in Java to implement the topological sorting algorithm. Assume that the vertices of the digraph are lowercase letters. The main() method in your program should prompt the user to enter the values of the adjacency matrix representing the digraph. The main() method should then print the adjacency matrix. Finally the main() method should call the topoSort() method to topologically sort the matrix. The topoSort() method should display the topologically sorted vertices of the digraph.

My code so far (please help me with calling topoSort() method to topologically sort the matrix):

import java.util.Scanner;

public class A10Q4_AlbiterMartinez {

static int nElems;

public static void main ( String[] args)

{

int arr[][];

arr=new int[10][10];

Scanner input= new Scanner(System.in);

System.out.print("Enter the number of vertices in the digraph (max of 10): " );

nElems=input.nextInt();

for(int i=0;i

for(int j=0;j

System.out.print("Enter the values for arr["+i+"]["+j+"]:");

arr[i][j]=input.nextInt();

}

}

input.close();

System.out.println("The Adjacency matrix is:");

for(int i = 0; i

for(int j = 0; j

System.out.print(arr[i][j] + " ");

}

System.out.println();

}

}

}

What the output should be:

Question: Write a program in Java to implement the topological sorting algorithm.

General Output Enter the number of vertices in the digraph (max of 10) 4 Enter the value for arr[0] [o] :0 Enter the value for arr[0 [1 1 Enter the value for arr[0] [2] :1 Enter the value for arr[0] [3] :0 Enter the value for arr[1] [0]0 Enter the value for arr[11 [1]:o Enter the value for arr[1] [2]:0 Enter the value for arr[1] [3] 0 Enter the value for arr [2] [0] : 0 Enter the value for arr[2] [1] :1 Enter the value for arr[2] [2] 0 Enter the value for arr [2] [3]:1 Enter the value for arr[3] [0]0 Enter the value for arr[3] [1] 1 Enter the value for arr [3] [2] : 0 Enter the value for arr[3] [3] :0 The Adjacency matrix is: 0 11 0 0 1 0 1 0 1 0 0 The Topologically Sorted Vertices are: a cdb Process completed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the topological sorting algorithm you can follow the steps below Ill update the code by adding the topoSort method and make necessary adj... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!