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:
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 completedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started