用栈实现求两点之间的所有路径:
// dfs.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stack>
#include <map>
#include <vector>
using namespace std;
#define NotFound -1
#define StartNode 0
#define EndNode 4
map<int,map<int,int>> visited;
map<int,vector<int>> ajdTable;
int isInStack[5];
//不在栈中且路径没有访问过
int getNextPoint(int point){
vector<int>::iterator it;
for ( it=ajdTable[point].begin() ; it != ajdTable[point].end(); it++ ){
if ((visited[point][*it]!=1) && (*it == EndNode))
return *it;
if ((visited[point][*it]!=1) && (isInStack[*it]!=1))
return *it;
}
return NotFound;
}
void setNoVisted(int point){
vector<int>::iterator it;
for ( it=ajdTable[point].begin() ; it != ajdTable[point].end(); it++ ){
visited[point][*it] = 0;
}