Skip to content

Instantly share code, notes, and snippets.

@LuckierDodge
Created November 30, 2016 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuckierDodge/19760376b5d0fc702e15264669f33b2a to your computer and use it in GitHub Desktop.
Save LuckierDodge/19760376b5d0fc702e15264669f33b2a to your computer and use it in GitHub Desktop.
#include "/home/cs340/progs/16f/p10/wdigraph.h"
void wdigraph::depth_first (int u) const
{
vector<bool> visited;
for(int i = 0; i < size; i++)
visited.push_back(false);
stack<int> travel;
travel.push(u);
while(!travel.empty())
{
bool found = false;
u = travel.top();
if(!visited[u])
cout << label[u];
visited[u] = true;
for(unsigned i = 0; i < adj_matrix[u].size(); i++)
{
if (adj_matrix[u][i] != 0 && !visited[i])
{
travel.push(i);
found = true;
cout << "->";
break;
}
}
if (found == false)
travel.pop();
}
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment