本文整理汇总了C++中graph::get_val方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::get_val方法的具体用法?C++ graph::get_val怎么用?C++ graph::get_val使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::get_val方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bfs
template < class T1, class T2 > bool bfs (graph < T1, T2 > &g, const T1 s, const T1 d, int player) // To find path connectivity b/w two nodes s and d
{
queue < T1 > list;
map < T1, bool > path;
map < T1, bool > visited;
vector < T1 > ver = g.get_nodes ();
for (auto it = ver.begin (); it != ver.end (); it++)
{
path[*it] = false;
visited[*it] = false;
}
list.push (s);
visited[s] = true;
while (!list.empty ())
{
T1 curr_node = list.front ();
list.pop ();
vector < T1 > adj_curr = g.adjecent (curr_node);
for (auto it = adj_curr.begin (); it != adj_curr.end (); it++)
{
if (g.get_val (*it) == player && !visited[*it])
{
path[*it] = true;
if (*it == d)
return true;
list.push (*it);
visited[*it] = true;
}
}
}
return false;
}
示例2: if
template < class T1, class T2 > void
disp (graph < T1, T2 > &g, int n) // Prints the board
{
int node_cnt = 0;
int space = 0;
char c;
for (int i = 0; i < n; i++)
{
for (int k = 0; k < space; k++)
cout << " ";
for (int j = 0; j < n; j++)
{
if (g.get_val (node_cnt) == 1)
c = 'B';
else if (g.get_val (node_cnt) == 2)
c = 'R';
else
c = '.';
if (j != n - 1)
{
cout << c << " - ";
++node_cnt;
}
else
{
cout << c;
++node_cnt;
}
}
cout << endl;
for (int m = 0; m < space; m++)
cout << " ";
if (i != n - 1)
print_slash (n);
space += 2;
}
}