Professional Documents
Culture Documents
undirected Graph G
of n vertices using backtracking principle
import java.util.*;
}
}
}
public boolean isPresent(int v)
{
for (int i = 0; i < pathCount - 1; i++)
if (path[i] == v)
return true;
return false;
}
public void display()
{
System.out.print("\nPath : ");
for (int i = 0; i <= n; i++)
System.out.print((path[i % n]+1) +" ");
System.out.println();
}
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Hamiltonian Cycle for an Undirected Graph\n");
HamiltonianCycle hc = new HamiltonianCycle();
System.out.println("Enter number of vertices\n");
int n = scan.nextInt();
System.out.println("\nEnter matrix\n");
int[][] graph = new int[V][V];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
graph[i][j] = scan.nextInt();
hc.findHamiltonianCycle(graph);
scan.close();
}
}