当前位置: 首页>>代码示例>>C++>>正文


C++ AdjList::begin方法代码示例

本文整理汇总了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);
}
开发者ID:palmerc,项目名称:lab,代码行数:25,代码来源:main.cpp

示例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;
        }
}
开发者ID:kwangiit,项目名称:matrix,代码行数:10,代码来源:matrix_client.cpp

示例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;
}
开发者ID:palmerc,项目名称:lab,代码行数:39,代码来源:main.cpp

示例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();
}
开发者ID:kwangiit,项目名称:matrix,代码行数:38,代码来源:matrix_client.cpp


注:本文中的AdjList::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。