本文整理汇总了C++中AdjList::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ AdjList::begin方法的具体用法?C++ AdjList::begin怎么用?C++ AdjList::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjList
的用法示例。
在下文中一共展示了AdjList::begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dijkstra
void dijkstra(AdjList &G, int start)
{
VertexList V;
list<int> S; // Discovered shortest paths
list<int> Q; // Pool of unknown vertices
V[start] = Vertex(0, 0, 1);
S.push_back(start);
for(AdjList::iterator i = G.begin(); i != G.end(); ++i)
if (i->first != start)
{
V[i->first] = Vertex(INT_MAX, 0, 0);
Q.push_back(i->first);
}
cout << "Shortest path discovered " << start << endl;
while (!Q.empty())
{
int u = extract_min(G, V, S);
cout << "Shortest path discovered " << u << endl;
V[u].known = 1;
S.push_back(u);
Q.remove(u);
}
print_out(V);
}
示例2: print_AdjList
void print_AdjList(AdjList &adj_list) {
for(AdjList::iterator it = adj_list.begin(); it != adj_list.end(); ++it) {
vector<int> exist_list = it->second;
cout << " " << it->first << " -> ";
for(int i = 0; i < exist_list.size(); i++) {
cout << " " << exist_list[i] << ",";
}
cout << endl;
}
}
示例3: main
int main(int argc, char* argv[])
{
ifstream in;
in.open(argv[1]);
boost::regex re_start("^\\s*s\\s+(\\d+)\\s*$", boost::regex::perl);
boost::regex re_vertex("^\\s*v\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*$", boost::regex::perl);
boost::cmatch matches;
AdjList G;
int start;
string str;
getline(in, str);
while ( in )
{
if (boost::regex_match(str.c_str(), matches, re_start))
start = boost::lexical_cast<int>(matches[1]);
else if (boost::regex_match(str.c_str(), matches, re_vertex))
{
int vertex = boost::lexical_cast<int>(matches[1]);
int node = boost::lexical_cast<int>(matches[2]);
int weight = boost::lexical_cast<int>(matches[3]);
// if node doesn't exist, create a linked list and attach the next item
if (G.find(vertex) == G.end()) // key doesn't exist
G[vertex] = new list<AdjNode>;
// if it does exist just add the next item and distance to the appropriate node
G[vertex]->push_back(AdjNode(node, weight));
}
getline(in, str);
}
in.close();
dijkstra(G, start);
cout << "Loops " << loop << endl;
for (AdjList::iterator i = G.begin(); i != G.end() ; ++i)
delete i->second;
G.clear();
return 0;
}
示例4: get_DAG
int get_DAG(AdjList &adj_list, TaskDAG &dag, string clientid) {
InDegree indegree;
for(AdjList::iterator it = adj_list.begin(); it != adj_list.end(); ++it) {
vector<int> exist_list = it->second;
int source_vertex = it->first;
if(indegree.find(source_vertex) == indegree.end()) {
indegree[source_vertex] = 0;
}
stringstream adj_ss;
for(int i = 0; i < exist_list.size(); i++) {
int dest_vertex = exist_list[i];
// add each vertex to string
adj_ss << exist_list[i] << clientid << "\'";
// update indegree count of each vertex in adjacency list
if(indegree.find(dest_vertex) == indegree.end()) {
indegree[dest_vertex] = 1;
}
else {
indegree[dest_vertex] = indegree[dest_vertex] + 1;
}
if(dag.find(dest_vertex) != dag.end()) {
TaskDAG_Value &value = dag[dest_vertex];
value.first = indegree[dest_vertex];
}
}
adj_ss << "\"";
string adjliststring(adj_ss.str()); // list of vertices delimited by \' with a final \"
// store info into DAG
TaskDAG_Value value(indegree[source_vertex], adjliststring);
dag[source_vertex] = value;
}
return indegree.size();
}