如何遍历图的顶点,而不是每个顶点都有单独的add.vertex? [英] How can I loop through a graph's vertices instead of having a separate add.vertex for each vertex?
本文介绍了如何遍历图的顶点,而不是每个顶点都有单独的add.vertex?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我下面的内容
void vader(int name)
{
vertices[size++] = new Vertex(name);
}
Graph graph = new Graph(7);
graph.vert(1);
graph.vert(2);
graph.vert(3);
graph.vert(4);
graph.vert(5);
graph.vert(6);
graph.vert(7);
除了让这7行代码添加7个顶点之外,还有什么方法能让我添加7个顶点的循环?
Instead of having these 7 lines of code to add 7 vertices is there any way I can have a loop that adds 7 vertices?
推荐答案
使用这样的for循环
Graph graph = new Graph(7);
for(int i=1;i<=7;i++){
graph.vert(i);
}
这篇关于如何遍历图的顶点,而不是每个顶点都有单独的add.vertex?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文