سلام عليكم
ممكن مساعدتي مطلوب برنامج بلغة جافا او حت ب سي هو به علاقة بهياكل بيانات ..يقوم بستخدام طابور (BreadthFirstSearch BFS هي استراتيجية العرض الاول) ادخال عقد .. لو كان اول عقدة 1 ثم 2 و3 و4 مصفوفة جوار
1 0 1 0
1 0 0 0
1 0 1 0
1 0 0 0
ناتج سيكون3 4 2 1
لان طابو يبحث عن البيانات او عقد بالعرض
انا وجدت حل في نت بس في خطا في دالة
class BFS{
private Queue<Integer> queue;
public void BFS()
{
queue = new LinkedList<>();
}
public void bbfs(int adjacency_matrix[][], int source)
{
int number_of_nodes = adjacency_matrix
int[] visited = new int[number_of_nodes + 1];
int i, element;
visited
queue.add(source);
while (!queue.isEmpty())
{
element = queue.remove();
i = element;
System.out.print(i + "\t");
while (i <= number_of_nodes)
{
if (adjacency_matrix[element][i] == 1 && visited[i] == 0)
{
queue.add(i);
visited[i] = 1;
}
i++;
} }
}
}
public class Samahrafa_bfs {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
BFS bfs = new BFS();
int number_no_nodes, source;
Scanner scanner = null;
try
{
System.out.println("Enter the number of nodes in the graph");
scanner = new Scanner(System.in);
number_no_nodes = scanner.nextInt();
int adjacency_matrix[][] = new int[number_no_nodes + 1][number_no_nodes + 1];
System.out.println("Enter the adjacency matrix");
for (int i = 1; i <= number_no_nodes; i++)
for (int j = 1; j <= number_no_nodes; j++)
adjacency_matrix[i][j] = scanner.nextInt();
System.out.println("Enter the source for the graph");
source = scanner.nextInt();
System.out.println("The BFS graph is ");