图的数据结构:邻接表
算法:递归+深度遍历
//栈s存路径
//栈l存弧的权值
stack<int> s;
stack<double>l;
void DFS(int start, int end)//找图上序号i,j点的所有路径
{
visited[start] = true;
s.push(start);
arclist *arc = node[start].firstarc;
//l.push(arc->weight);
while (arc)
{
if (start == end)//找到终点
{
//输出栈顶到栈底所有元素
//l.pop();
outputstack(s, l);//输出栈中内容
s.pop();
visited[start] = false;//标记取消;
break;
}
// l.pop();
// l.push(arc->weight);
int j = arc->archead;//弧头节点
if (!visited[j])//节点未访问
{
DFS(j, end);
}
if (arc->nextarc == NULL)//节点无其他出度
{
s.pop();//栈顶元素出栈
// l.pop();
visited[start] = false;
}
arc = arc->nextarc;
}
}