From d3b3ad2741b6e8962b397dbdbbe2631c2c11312c Mon Sep 17 00:00:00 2001 From: Rohit Singh <62849015+Rohit-Singh-Ch@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:16:20 +0530 Subject: [PATCH] Create detect Cycle in Graph by BFS --- detect Cycle in Graph by BFS | 130 +++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 detect Cycle in Graph by BFS 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