// C++ version of GraphAlgs.java --- mjd@cs.auckland.ac.nz // // July 2007 // // edit Dec 2010: getBFSparents (parent of roots set to -1 and do forest) // #include #include "Graph.h" void getBFSparents(const Graph &G, int v, int parent[]) { int n = G.order(); if (parent[v]!=-2) // initialize for forest BFS for (int i=0; i toGrow; parent[v]=-1; toGrow.push(v); while (!toGrow.empty()) { int grow = toGrow.front(); toGrow.pop(); const NLIST nbrs = G.neighbors(grow); for (int i=0; i toGrow; int cnt = 0; LevelOrder[v] = ++cnt; toGrow.push(v); while (!toGrow.empty()) { int grow = toGrow.front(); toGrow.pop(); const NLIST nbrs = G.neighbors(grow); for (int i=0; i 0) span[j] = true; const NLIST nbrs = G.neighbors(j); for (int k=0; k < nbrs.size(); k++) { int u = nbrs[k]; if (// PreOrder[u] < PreOrder[j] && PostOrder[u] > PostOrder[j] ) return false; // Bingo! // note: PreOrder[u] > 0 since u is reachable from j } } if (cnt == n) break; // all vertices spanned } return true; } int maxDistance(const Graph &G, int v, int dist[]) { int n = G.order(); for (int i=0; i 0 ) { depth++; nextList.clear(); for (int e=0; e max ? d : max; } free(dist); return max; }