Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  DFSApp.java
Language: JAVA
Code:

import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JOptionPane;
public class DFSApp extends JOptionPane
{
    public static void main(String[] args) throws IOException

    {
 
 
       Graph theGraph = new Graph();

      
       int option;
        String opt=null;
        opt=JOptionPane.showInputDialog("Welcome"+"\n"+"Enter 1 for DFS"+"\n"+"Enter 2 for BFS");

        option=Integer.parseInt(opt);

        FileReader fr =new FileReader("D:\\matrix.txt");

        BufferedReader br =new BufferedReader (fr);

        int mat[][] =new int [50][50];
        for(int i=0;i<= 50;i++)

        {

            for(int j=0;j<=50;j++)
            {

                mat[i][j]= br.read();

            }
        }

        

         System.out.println("Here is the matrix: ");

           for (int i = 0; i < 50; i++){

               for (int j = 0; j < 50; j++){

                   System.out.print(mat[i][j]);

     
      theGraph.addVertex("A");// 0  (start for dfs)

      theGraph.addVertex("B");    // 1

      theGraph.addVertex("C");    // 2

     theGraph.addVertex("D");    // 3

      theGraph.addVertex("E");

      theGraph.addEdge(1, 3);     // AB

      theGraph.addEdge(1, 5);     // BC

      theGraph.addEdge(0, 3);     // AD

      theGraph.addEdge(0, 2);     // DE

      theGraph.addEdge(3, 0);

      theGraph.addEdge(5, 1);

      System.out.println("visit in DFS :");

      theGraph.dfs();

      System.out.println();

     
      System.out.println("\n"+"visits in bfs :");
      theGraph.bfs();

               }

     

              }}

    public void init()

    {

   

    }

 

}

       
Comments: