本文整理汇总了C++中vmap::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ vmap::begin方法的具体用法?C++ vmap::begin怎么用?C++ vmap::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vmap
的用法示例。
在下文中一共展示了vmap::begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prim
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;
}
示例2: 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!";
}
示例3:
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;
}
示例4: clearAll
void Graph::clearAll(){
for(vmap::iterator it = vertexMap.begin(); it != vertexMap.end(); it++)
(*it).second->reset();
}