本文整理汇总了C++中TQueue::pop方法的典型用法代码示例。如果您正苦于以下问题:C++ TQueue::pop方法的具体用法?C++ TQueue::pop怎么用?C++ TQueue::pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TQueue
的用法示例。
在下文中一共展示了TQueue::pop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OutputQueue
void OutputQueue(TQueue queue)
{
typename TQueue::key_map propertyMap = queue.keys();
// Read out the queue, saving the objects in the order they were in the queue
while(!queue.empty())
{
typename TQueue::value_type queuedObject = queue.top();
std::cout << "queuedObject: " << queuedObject << " ";
typename boost::property_traits<typename TQueue::key_map>::value_type value = get(propertyMap, queuedObject);
std::cout << " value: " << value << std::endl;
queue.pop();
}
}
示例2: DFS
void DFS(const TGraph& g, int v, TLine* result) {
result->resize(g.size());
fill(result->begin(), result->end(), -1);
TQueue q;
(*result)[v] = 0;
q.push(v);
while (!q.empty()) {
int now = q.front();
q.pop();
for (int i = 0; i < g[now].size(); ++i) {
int next = g[now][i];
if (-1 == (*result)[next]) {
(*result)[next] = (*result)[now] + 1;
q.push(next);
}
}
}
}
示例3: levelOrder
void TwoThreeTree::levelOrder() {
if (root == NULL) return;
// Use a tree to do levelOrder Traversal
TQueue queue;
queue.push(root);
root->level = 0;
cout << "Level Order Traversal:\n";
int currentLevel = 0;
while (!queue.isEmpty()) {
const TNode *t = queue.top();
if (t->level != currentLevel) {
cout << endl;
currentLevel = t->level;
}
// push t's children on queue, set their level nubmer
t->print();
if (!t->isLeaf) {
int nextLevel = t->level + 1;
t->left->level = nextLevel;
queue.push(t->left);
t->middle->level = nextLevel;
queue.push(t->middle);
if (t->rlow != -1) {
t->right->level = nextLevel;
queue.push(t->right);
}
}
queue.pop();
}
cout << endl << endl;
}
示例4: main
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n = ReadInt();
int m = ReadInt();
int s = ReadInt() - 1;
int f = ReadInt() - 1;
TGraph g(n);
for (int i = 0; i < m; ++i) {
int begin = ReadInt() - 1;
int end = ReadInt() - 1;
int cost = ReadInt();
double p = 1.0 - static_cast<double>(cost) / 100.0;
g[begin].push_back( TNode(end, p) );
g[end].push_back( TNode(begin, p) );
}
/*
for (int i = 0; i < n; ++i) {
shuffle(g[i].begin(), g[i].end(), default_random_engine());
}
*/
const TCost INF(n + 1000, -10.0);
TCosts costs(n, INF);
TIntegers parent(n, -1);
parent[s] = -2;
TQueue q;
{
const TCost cost(0, 1.0);
q.push(s);
costs[s] = cost;
}
while (!q.empty()) {
const int now = q.front();
q.pop();
if (now == f) {
break;
}
const TCost& nowCost = costs[now];
for (TNodes::const_iterator toNode = g[now].begin(); toNode != g[now].end(); ++toNode) {
const int next = toNode->_to;
TCost nextCost(nowCost._iDist + 1, nowCost._fine*toNode->_p);
if (-1 == parent[next] || ((nowCost._iDist + 1 == costs[next]._iDist) && (nowCost._fine*toNode->_p > costs[next]._fine))) {
if (-1 == parent[next]) {
q.push(next);
}
costs[next] = nextCost;
parent[next] = now;
}
}
}
TIntegers path;
int now = f;
while (-2 != now) {
path.push_back(now);
now = parent[now];
}
printf("%d %.12lf\n", path.size(), 1.0 - costs[f]._fine);
for (TIntegers::const_reverse_iterator toPath = path.rbegin(); toPath != path.rend(); ++toPath) {
printf("%d ", *toPath + 1);
}
printf("\n");
return 0;
}