please tell me whats wrong with this code/ please fix it ( in C) #include #include #define MAXIMUM 100 #define intial 1 #define waitng 2 #define visiited 3 int n; int adj[MAXIMUM][MAXIMUM]; int state[MAXIMUM]; void create_Graph(); void breadth_First_Search_Traversal(); void breadth_First_Search(int v); int que[MAXIMUM], frnt = -1,rearr = -1; void insert-Queue(int vertex); int delete_Queue(); int is_Empty_Queue(); int main() { create_Graph(); breadth_First_Search_Traversal(); return 0; } void breadth_First_Search_Traversal() { int h; for(h=0; h rearr) return 1; else return 0; } int delete_Queue() { int deleteitem; if(frnt == -1 || frnt > rearr) { printf("Queue Underflow\n"); exit(1); } deleteitem = que[frnt]; frnt = frnt+1; return deleteitem; } void create_Graph() { int cnt,max_Edge,orgn,destn; printf("Enter number of vertices : "); scanf("%d",&n); max_Edge = n*(n-1); for(cnt=1; cnt<=max_Edge; cnt++) { printf("Enter edge %d( -1 -1 to quit ) : ",cnt); scanf("%d %d",&orgn,&destn); if((orgn == -1) && (destn == -1)) break; if(orgn>=n || destn>=n || orgn<0 || destn<0) { printf("Invalid edge!\n"); cnt--; } else { adj[orgn][destn] = 1; } } }
please tell me whats wrong with this code/ please fix it ( in C)
#include<stdio.h>
#include<stdlib.h>
#define MAXIMUM 100
#define intial 1
#define waitng 2
#define visiited 3
int n;
int adj[MAXIMUM][MAXIMUM];
int state[MAXIMUM];
void create_Graph();
void breadth_First_Search_Traversal();
void breadth_First_Search(int v);
int que[MAXIMUM], frnt = -1,rearr = -1;
void insert-Queue(int vertex);
int delete_Queue();
int is_Empty_Queue();
int main()
{
create_Graph();
breadth_First_Search_Traversal();
return 0;
}
void breadth_First_Search_Traversal()
{
int h;
for(h=0; h<n; h++)
state[h] = intial;
printf("Enter Start Vertex for breadth_First_Search: \n");
scanf("%d", &h);
breadth_First_Search(h);
}
void breadth_First_Search(int h)
{
int i;
insert-Queue(h);
state[h] = waitng;
while(!is_Empty_Queue())
{
h= delete_Queue( );
printf("%d ",h);
state[h] = visiited;
for(i=0; i<n; i++)
{
if(adj[h][i] == 1 && state[i] == intial)
{
insert-Queue(i);
state[i] = waitng;
}
}
}
printf("\n");
}
void insert-Queue(int vertex)
{
if(rearr == MAXIMUM-1)
printf("Queue Overflow\n");
else
{
if(frnt == -1)
frnt = 0;
rearr = rearr+1;
que[rearr] = vertex ;
}
}
int is_Empty_Queue()
{
if(frnt == -1 || frnt > rearr)
return 1;
else
return 0;
}
int delete_Queue()
{
int deleteitem;
if(frnt == -1 || frnt > rearr)
{
printf("Queue Underflow\n");
exit(1);
}
deleteitem = que[frnt];
frnt = frnt+1;
return deleteitem;
}
void create_Graph()
{
int cnt,max_Edge,orgn,destn;
printf("Enter number of vertices : ");
scanf("%d",&n);
max_Edge = n*(n-1);
for(cnt=1; cnt<=max_Edge; cnt++)
{
printf("Enter edge %d( -1 -1 to quit ) : ",cnt);
scanf("%d %d",&orgn,&destn);
if((orgn == -1) && (destn == -1))
break;
if(orgn>=n || destn>=n || orgn<0 || destn<0)
{
printf("Invalid edge!\n");
cnt--;
}
else
{
adj[orgn][destn] = 1;
}
}
}
Step by step
Solved in 4 steps with 5 images