Skip to content

Commit

Permalink
Merge pull request ReciHub#382 from izmcm/patch-1
Browse files Browse the repository at this point in the history
Create interative_dfs.cpp
  • Loading branch information
OtacilioN authored Oct 22, 2019
2 parents 3132ec5 + eb3d318 commit 35c180d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions dfs/interative_dfs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Algoritmo que realiza busca exaustiva num grafo, começando por um vértice inicial v e visitando
o máximo possivel seu ramo até retroceder para visitar outro ramo até que todos os vértices tenham
sido visitados
*/
#include <bits/stdc++.h>
using namespace std;

#define NODES 10

vector<int> adj[NODES];
int visit[NODES];

void dfs(int v){
stack<int> pilha;
pilha.push(v);

while(!pilha.empty()){
int now = pilha.top();
pilha.pop();

visit[now] = 1;

for(int i = 0; i < adj[now].size(); i++){
int next = adj[now][i];

if(visit[next] == 0)
pilha.push(next);
}
}
}

int main(){
dfs(initialNode);
}

0 comments on commit 35c180d

Please sign in to comment.