本文整理汇总了C++中Vertices::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Vertices::insert方法的具体用法?C++ Vertices::insert怎么用?C++ Vertices::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isConnected
bool Graph::isConnected (Vertices *V)
{
Vertices *nextVertices = new Vertices();
int reachedsize = 1;
bool first = true;
for (Vertices::iterator it = V->begin(); it != V->end(); ++it)
{
int v = *it;
if (first)
{
nextVertices->insert(v);
reachedVertices[v] = true;
first = false;
}
else { reachedVertices[v] = false; }
}
while (!nextVertices->empty())
{
Vertices::iterator it = nextVertices->end(); --it;
int currentVertex = *it;
nextVertices->erase(it);
Vertices *adjList = adjacencySets[currentVertex];
for (Vertices::iterator it = adjList->begin(); it != adjList->end(); ++it) {
int adjV = *it;
if (V->find(adjV) != V->end())
{
if (!reachedVertices[adjV]) {
reachedVertices[adjV] = true;
reachedsize++;
nextVertices->insert(adjV);
}
}
}
}
delete nextVertices;
return reachedsize == (int) V->size();
}
示例2: get_leaves
/** Returns the set of all leaf nodes in the forest. */
Vertices get_leaves() const {
Vertices retval;
for (size_t i=0; i<levels.size(); ++i) {
const Vertices &vertices = vertices_at_level(i);
for (Vertices::const_iterator vi=vertices.begin(); vi!=vertices.end(); ++vi) {
if ((*vi)->children.empty())
retval.insert(*vi);
}
}
return retval;
}
示例3: Vertices
Vertices *Graph::getAdjacentVertices (int v, int vMax)
{
if (vMax == -1) { vMax = v; }
Vertices *adjVertices = new Vertices();
Vertices *adjSet = adjacencySets[v];
for (Vertices::iterator it = adjSet->begin(); it != adjSet->end(); ++it)
{
int adjV = *it;
if (adjV < vMax) { adjVertices->insert(adjV); }
}
return adjVertices;
}
示例4: buildDataStructure
void GraphComponent::buildDataStructure ()
{
for (int index = 0; index < size; index++)
{
int firstVertex = vertices[index];
Datatree *tree = new Datatree(firstVertex);
Vertices *firstVertices = new Vertices();
firstVertices->insert(firstVertex);
std::list<TreeToAdd> treeToAddList;
struct TreeToAdd firstTreeToAdd = {tree,0,firstVertices,0};
treeToAddList.push_back(firstTreeToAdd);
while (!treeToAddList.empty())
{
struct TreeToAdd treeToAdd = treeToAddList.front();
Datatree *node = treeToAdd.node;
Vertices *vertices = treeToAdd.vertices;
treeToAddList.pop_front();
if (VERBOSE) {
for (int i = 0; i < VERBOSE_TAB; i++) { std::cout << "..."; }
std::cout << "(" << VERBOSE_TAB << ") CURRENTLY ON NODE ";
node->printVertices();
VERBOSE_TAB++;
}
Vertices *adjVertices = graph->getAdjacentVertices(node->vertex,graph->size);
for (Vertices::iterator it = adjVertices->begin(); it != adjVertices->end(); ++it)
{
int childVertex = *it;
if (order->at(childVertex) >= order->at(firstVertex) && vertices->find(childVertex) == vertices->end())
{
vertices->insert(childVertex);
Datatree *child = node->addChild(childVertex);
Vertices *childVertices = new Vertices(*vertices);
struct TreeToAdd childTreeToAdd = {child,0,childVertices,0};
treeToAddList.push_back(childTreeToAdd);
if (node->wholeSet)
{
datatree->parent = child;
child->wholeSet = true;
node->wholeSet = false;
}
}
}
delete adjVertices;
delete vertices;
if (VERBOSE) { VERBOSE_TAB--; }
}
treeToAddList.clear();
struct TreeToAdd newTreeToAdd = {datatree,tree,new Vertices (),0};
treeToAddList.push_back(newTreeToAdd);
while (!treeToAddList.empty())
{
struct TreeToAdd treeToAdd = treeToAddList.front();
Datatree *node = treeToAdd.node;
Datatree *nodeToAdd = treeToAdd.nodeToAdd;
Vertices *vertices = treeToAdd.vertices;
// Vertices *adjVertices = treeToAdd.adjVertices;
treeToAddList.pop_front();
if (VERBOSE) {
for (int i = 0; i < VERBOSE_TAB; i++) { std::cout << "..."; }
std::cout << "(" << VERBOSE_TAB << ") ADJUSTING NODE ";
node->printVertices(false);
std::cout << " WITH ";
nodeToAdd->printVertices(false);
std::cout << " KNOWING ";
graph->printVertices(vertices);
std::cout << std::endl;
VERBOSE_TAB++;
}
if (vertices->find(nodeToAdd->vertex) == vertices->end())
{
node = node->addChild(nodeToAdd->vertex);
vertices->insert(nodeToAdd->vertex);
}
for (TreesSet::iterator it = nodeToAdd->children->begin(); it != nodeToAdd->children->end(); ++it)
{
Datatree *child = *it;
if (vertices->find(child->vertex) == vertices->end())
{
Vertices *childVertices = new Vertices (*vertices);
struct TreeToAdd childToAdd = {node,child,childVertices,0};
treeToAddList.push_back(childToAdd);
vertices->insert(child->vertex);
}
}
if (nodeToAdd->parent != 0)
//.........这里部分代码省略.........