voidDFS(ALGraph G,int v){
visited[v]=1;printf("%c ", G.vertices[v].data);for(ArcNode* cur = G.vertices[v].firstarc; cur !=nullptr; cur = cur->nextarc){if(!visited[cur->adjvex])DFS(G, cur->adjvex);}}
2.非递归
#include<stack>#include<iostream>usingnamespace std;voidDFS(ALGraph G,int v){
visited[v]=1;printf("%c ", G.vertices[v].data);
stack<ArcNode*> st;
ArcNode* cur = G.vertices[v].firstarc;int index =0;while(cur ||!st.empty()){while(cur){
index = cur->adjvex;if(!visited[index]){
st.push(cur);
visited[index]=1;printf("%c ", G.vertices[index].data);
cur = G.vertices[index].firstarc;}else
cur = cur->nextarc;}if(st.empty())break;
cur = st.top();
st.pop();
cur = cur->nextarc;}}
算法题常用API
std::accumulate
函数原型:
template< class InputIt, class T >
T accumulate( InputIt first, InputIt last, T init );一般求和的,代码如下:
int sum accumulate(vec.begin() , vec.end() , 0);详细用法参考
lo…
在VScode里面添加PHP Debug 插件,根据debug描述内容操作 1: 随意在index里面写个方法,然后用浏览器访问你的hello 方法,正常会进入下边的内容
class IndexController
{public function index(){return 您好!这是一个[api]示例应用;}public function hello() {phpin…