diff --git a/detect Cycle in Graph by BFS b/detect Cycle in Graph by BFS new file mode 100644 index 00000000..36631f2b --- /dev/null +++ b/detect Cycle in Graph by BFS @@ -0,0 +1,130 @@ +-1--->if any vertex unvisited + 0---->if any vertex visited and push into the stack + 1---->if any vertex poped(means already complete don't considered) + + if any vertex alreay adjacency visited and not poped means in 0 position then graph conation cycle + + + + #include + #include + #define v 5 + int arr[v][v]; + int visited[v]; + int stack[v]; + int top=-1; + + void push(int data) + { + stack[++top]=data; + } + + int pop() + { + return stack[top--]; + } + + int peek() + { + return stack[top]; + } + + void Dfs() + { + int i,x,y,flag=0; + while(top!=-1) + { + for(i=0;i