本文整理汇总了C++中vmap类的典型用法代码示例。如果您正苦于以下问题:C++ vmap类的具体用法?C++ vmap怎么用?C++ vmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: clearAll
void Graph::unweighted( const string & startName )
{
clearAll( );
vmap::iterator itr = vertexMap.find( startName );
if( itr == vertexMap.end( ) )
{
cout << startName << " is not a vertex in this graph" << endl;
return;
}
Vertex *start = (*itr).second;
list<Vertex *> q;
q.push_back( start ); start->dist = 0;
while( !q.empty( ) )
{
Vertex *v = q.front( ); q.pop_front( );
for( int i = 0; i < v->adj.size( ); i++ )
{
Vertex *w = v->adj[ i ];
if( w->dist == INFINITY )
{
w->dist = v->dist + 1;
w->path = v;
q.push_back( w );
}
}
}
}
开发者ID:piaoyimq,项目名称:CppSpace,代码行数:32,代码来源:Graph1.cpp
示例2: getVertex
Vertex* Graph::getVertex (vdata v)
{
vmap::iterator it = vertexMap.find (v);
if (it == vertexMap.end()) {
return addVertex (v);
}
return (*it).second;
}
开发者ID:Azizou,项目名称:UVa-online-judge,代码行数:10,代码来源:10608.cpp
示例3: getVertex
Vertex* BinaryTree::getVertex (int v)
{
vmap::iterator it = vertexMap.find (v);
if (it == vertexMap.end()) {
return addVertex (v);
}
return (*it).second;
}
开发者ID:Azizou,项目名称:UVa-online-judge,代码行数:10,代码来源:122.cpp
示例4: getVertex
Vertex* Graph::getVertex(const string& s){
vmap::const_iterator it = vertexMap.find(s);
if(it == vertexMap.end()){
Vertex* v = new Vertex(s);
vertexMap[s] = v;
return v;
}
return (*it).second;
}
开发者ID:keshavnandan,项目名称:Hackerrank,代码行数:11,代码来源:dynamicGraph.cpp
示例5: Vertex
// If vertexName is not present, add it to vertexMap
// In either case, return the Vertex
Vertex * Graph::getVertex( const string & vertexName )
{
vmap::iterator itr = vertexMap.find( vertexName );
if( itr == vertexMap.end( ) )
{
Vertex *newv = new Vertex( vertexName );
allVertices.push_back( newv );
vertexMap.insert( vpair( vertexName, newv ) );
return newv;
}
return (*itr).second;
}
开发者ID:piaoyimq,项目名称:CppSpace,代码行数:15,代码来源:Graph1.cpp
示例6: addvertex
void graph::addvertex(const string &name)
{
vmap::iterator itr=work.begin();
itr=work.find(name);
if(itr==work.end())
{
vertex *v;
v= new vertex(name);
work[name]=v;
return;
}
cout<<"\nVertex already exists!";
}
开发者ID:jindal25,项目名称:Coding4cpp,代码行数:13,代码来源:graph_dictionary.cpp
示例7: printPath
void Graph::printPath( const string & destName ) const
{
vmap::const_iterator itr = vertexMap.find( destName );
if( itr == vertexMap.end( ) )
{
cout << "Destination vertex not found" << endl;
return;
}
const Vertex & w = *(*itr).second;
if( w.dist == INFINITY )
cout << destName << " is unreachable";
else
printPath( w );
cout << endl;
}
开发者ID:piaoyimq,项目名称:CppSpace,代码行数:17,代码来源:Graph1.cpp
示例8: construct_hits_map
map<mmddyyyy, UI> construct_hits_map(const vmap &r)
{
map<mmddyyyy, UI> k;
// construct map of dates and number of visits in each date
for(vmap::const_iterator i = r.begin(); i!=r.end(); i++)
{
for(dvec::const_iterator j = i->second.begin(); j!=i->second.end(); j++)
{
if(k.find(*j)==k.end())
k[*j] = 1;
else
k[*j]++;
}
}
// erase unwanted elements
mmddyyyy td = k.rbegin()->first;
td.yyyy--; // this serves as the upper bound for erasure
k.erase(k.begin(), k.upper_bound(td));
return k;
}
开发者ID:hansongjing,项目名称:Old-Projects,代码行数:23,代码来源:barchart.cpp
示例9: clearAll
long long Graph::prim(const string& s){
vmap::const_iterator itr = vertexMap.find(s);
if(itr == vertexMap.end())
cerr<<"Source vertex not found"<<endl;
clearAll();
int n = vertexMap.size() - 1;
Vertex *p = itr->second;
vector<Vertex*> Q;
// priority_queue<Vertex*, vector<Vertex*>, Compare> Q;
p->dist = 0;
for(vmap::const_iterator it = vertexMap.begin(); it != vertexMap.end(); it++)
Q.push_back(it->second);
long long cost = 0;
while(!Q.empty()){
make_heap(Q.begin(), Q.end(), Compare());
Vertex *u = Q.front();
u->done = true;
pop_heap(Q.begin(), Q.end(), Compare());
Q.pop_back();
for(vector<Edge>::const_iterator it = u->adj.begin(); it != u->adj.end(); it++){
Vertex *v = it->dest;
if(!v->done && v->dist > it->cost){
v->dist = it->cost;
v->prev = u;
// cout<<"cost of "<<v->name<<" is updated to "<<v->dist<<endl;
}
}
}
for(vmap::const_iterator it = vertexMap.begin(); it != vertexMap.end(); it++){
cost+=it->second->dist;
}
return cost;
}
开发者ID:keshavnandan,项目名称:Hackerrank,代码行数:39,代码来源:dynamicGraph.cpp
示例10: isVertex
bool Graph::isVertex(const string& s) const {
vmap::const_iterator it = vertexMap.find(s);
if(it == vertexMap.end()) return false;
return true;
}
开发者ID:keshavnandan,项目名称:Hackerrank,代码行数:6,代码来源:dynamicGraph.cpp
示例11: addedge
void graph::addedge(const string& from, const string& to, double cost)
{
vertex *f=(work.find(from)->second);
vertex *t=(work.find(to)->second);
pair<int,vertex *> edge = make_pair(cost,t);
f->adj.push_back(edge);
}
开发者ID:jindal25,项目名称:Coding4cpp,代码行数:7,代码来源:graph_dictionary.cpp
示例12: getVertex
Vertex* WGraph::getVertex (vdata v) {
it = vertexMap.find (v);
if (it == vertexMap.end())
return addVertex (v);
return it->second;
}
开发者ID:Azizou,项目名称:UVa-online-judge,代码行数:8,代码来源:10801.cpp
示例13: addVertex
Vertex* Graph::addVertex (vdata v, bool waken = false) {
Vertex* newv = new Vertex (v);
newv->waken = waken;
allVertexes.push_back (newv);
vertexMap.insert (vpair (v, newv));
return newv;
}
开发者ID:Azizou,项目名称:UVa-online-judge,代码行数:7,代码来源:10507.cpp
示例14: addVertex
Vertex* Graph::addVertex (vdata v) {
Vertex* newv = new Vertex (v);
allVertexes.push_back (newv);
vertexMap.insert (vpair (v, newv));
return newv;
}
开发者ID:Azizou,项目名称:UVa-online-judge,代码行数:6,代码来源:10608.cpp
示例15: addVertex
Vertex* BinaryTree::addVertex (int v) {
Vertex* newv = new Vertex (v);
allVertexes.push_back (newv);
vertexMap.insert (vpair (v, newv));
return newv;
}
开发者ID:Azizou,项目名称:UVa-online-judge,代码行数:6,代码来源:122.cpp
注:本文中的vmap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论