本文整理汇总了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;
}
示例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;
}