本文整理汇总了C++中ArraySet::Insert方法的典型用法代码示例。如果您正苦于以下问题:C++ ArraySet::Insert方法的具体用法?C++ ArraySet::Insert怎么用?C++ ArraySet::Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArraySet
的用法示例。
在下文中一共展示了ArraySet::Insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ComputeConnectedComponents
void GraphTools::ComputeConnectedComponents(vector<vector<int>> const &adjacencyList, vector<vector<int>> &vComponents) {
vComponents.clear();
if (adjacencyList.empty()) return;
size_t componentCount(0);
size_t uNumVertices(adjacencyList.size());
vector<bool> evaluated (uNumVertices, false);
ArraySet currentSearch(uNumVertices);
ArraySet remaining (uNumVertices);
for (int vertex = 0; vertex < uNumVertices; ++vertex) {
remaining.Insert(vertex);
}
// add first vertex, from where we start search
int const startVertex(0);
currentSearch.Insert(startVertex);
remaining.Remove(startVertex);
componentCount++;
vComponents.resize(componentCount);
while (!remaining.Empty() && !currentSearch.Empty()) {
int const nextVertex(*currentSearch.begin());
evaluated[nextVertex] = true;
vComponents[componentCount - 1].push_back(nextVertex);
currentSearch.Remove(nextVertex);
remaining.Remove(nextVertex);
for (int const neighbor : adjacencyList[nextVertex]) {
if (!evaluated[neighbor]) {
currentSearch.Insert(neighbor);
}
}
if (currentSearch.Empty() && !remaining.Empty()) {
int const startVertex = *remaining.begin();
currentSearch.Insert(startVertex);
remaining.Remove(startVertex);
componentCount++;
vComponents.resize(componentCount);
}
}
}