```
import java.util.ArrayList;
import java.io.*;
import java.util.*;
import java.util.Graph;
public class Graph
{
public int[][] adjMatrix;//Edges will be represented as adjacency Matrix
int size;
}
public Graph(int size)
{
adjMat = new boolean[size][size];
for (int i=0; i < adjMat.length; i++)
{
for (int j=0; j < adjMat.length; j++)
{
adjMat[i][j] = false;
}
}
}
//This method will be called to make connect two nodes
public void connectNode(Node start,Node end)
{
if(adjMatrix==null)
{
size=nodes.size();
adjMatrix=new int[size][size];
}
public void add(int 0, int 6)
{
adjMat[0][6] = true;
}
// The frontier is an ArrayList of Paths.
ArrayList<Path> frontier = new ArrayList<Path>();
// Initially the frontier contains just the Path
// containing only the start node.
Path firstPath = new Path(start);
frontier.add(firstPath);
// Search until the goal is found,
// or the frontier is empty.
while (!frontier.isEmpty()) {
while (!frontier.isEmpty())
{
currentNode = frontier.poll();
explored.add(currentNode);
for (Node node : currentNode.children) {//adding node children to fronier and checking if they are goal
if (!frontier.contains(node) || !explored.contains(node)) {
frontier.add(node);
prev.put(node, currentNode);//mapping nodes to parent node to return sequence of nodes
if (node.isGoal) {
goalNode = node;
break;
}
}
}
}
return false;
}
public static void main(String[] args)
{
Graph g = new Graph(7);
// Add edges to the Graph
g.add(0, 1);
g.add(0, 2);
g.add(1,5);
g.add(1,6);
g.add(2, 3);
g.add(3, 4);
// select a search type
boolean depthFirst = true;
// start searching
g.search(0,4, depthFirst);
}
```

Aakanksha_1 0 Newbie Poster

rproffitt 2,605 "Nothing to see here." Moderator

shweta_4 0 Newbie Poster

rproffitt 2,605 "Nothing to see here." Moderator

AssertNull 1,094 Practically a Posting Shark

rproffitt commented: Obvious +1 +0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.