DSLab Prog11
DSLab Prog11
#include <stdio.h>
#include <stdlib.h>
// Global Variables
int adjMatrix[MAX][MAX]; // Adjacency matrix to store the graph
int visited[MAX]; // Array to keep track of visited cities
int n; // Number of cities
// BFS function
void BFS(int startCity) {
int queue[MAX], front = 0, rear = -1, i;
visited[startCity] = 1;
queue[++rear] = startCity;
// Main function
int main() {
int choice, startCity;
createGraph();
printf("Enter the starting city number between 0 and %d: ", n-1);
scanf("%d", &startCity);
if (choice == 1) {
printf("Cities reachable from city %d using DFS:\n", startCity);
DFS(startCity);
} else if (choice == 2) {
printf("Cities reachable from city %d using BFS:\n", startCity);
BFS(startCity);
} else {
printf("Invalid choice!\n");
}
return 0;
}