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


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

本文整理汇总了C++中AdjList::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ AdjList::clear方法的具体用法?C++ AdjList::clear怎么用?C++ AdjList::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AdjList的用法示例。


在下文中一共展示了AdjList::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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

示例2: main

int main(int argc, char *argv[]) {


  std::string input;
  int width;
  int height;
  int row = 0;
  int attempt = 0;

  while(std::getline(std::cin, input)) {
    char c = input.at(0);
    if(c == '.' || c == 'X' || c == '*') {
      ++row;
      neighbors.clear();
      for(int pos = 0; pos < (int) input.length(); ++pos) {
        VertexWeight vertexWeight;
        vertexWeight.first = pos;
        char temp = input.at(pos);
        if(temp == '.') {
          vertexWeight.second = 1;
        } else if(temp == '*') {
          vertexWeight.second = 2;
        } else {
          vertexWeight.second = 3;
        }
        neighbors.push_back(vertexWeight);
      }
      adjList.push_back(neighbors);
      if(height == row) {
        visited.clear();
        for(int index = 0; index < height; ++index) {
          visited.push_back(std::vector<bool>(width, false));
        }
        for(int i = 0; i < height; ++i) {
          for(int j = 0; j < width; ++j) {
            if((visited[i])[j] == false && ((adjList[i])[j]).second != 1) {
              area = 0;
              floodFill(i, j, ((adjList[i])[j]).second);
              if(area)
              areas.push_back(area);
            }
          }
        }

        std::cout << "Throw " << ++attempt << std::endl;
        std::sort(areas.begin(), areas.end());
        int numAreas = (int)areas.size() - 1;
        for(std::vector<int>::iterator it = areas.begin(); it != areas.end(); ++it) {
          std::cout << *it;
          if(numAreas--) {
            std::cout << " ";
          }
        }
        std::cout << std::endl;
        std::cout << std::endl;
      }
    } else {
      row = 0;

      std::stringstream sbuf;
      sbuf << input;
      sbuf >> width >> height;

      adjList.clear();
      areas.clear();

      if(width == 0 && height == 0) {
        break;
      }
    }
  }
  return 0;
}
开发者ID:chaitanyav,项目名称:UVA,代码行数:73,代码来源:657_the_die_is_cast.cpp


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