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


C++ PriorityQueue::empty方法代码示例

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


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

示例1: main

int main()
{
  // print my name and this assignment's title 
  cout << "LAB 11a: Write And Test A Priority Queue Template\n"; 
  cout << "Programmer: Jacky Chow\n"; 
  cout << "Editor(s) used: Notepad++\n"; 
  cout << "Compiler(s) used: Visual C++\n"; 
  cout << "File: " << __FILE__ << endl; 
  cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
  
  PriorityQueue<int> pq;
  int temp;
  cout << "Created a PriorityQueue<int> named pq\n";
  cout << "Its size should be 0. It is: " << pq.size() << endl; 
  assert(0 == pq.size());
  if(pq.empty()) cout << "pq.empty() returned true that it was empty\n";
  else cout << "Error: pq.empty() returned false for empty PQ\n";
  assert(pq.empty());
  cout << "\nEnqueuing the ints 13, 8, 4, 20, 10 into pq\n";
  pq.enqueue(13);
  pq.enqueue(8);
  pq.enqueue(4);
  pq.enqueue(20);
  pq.enqueue(10);
  
  if(!pq.empty()) cout << "pq.empty() returned false that it was empty\n";
  else cout << "Error: pq.empty() returned true for a non-empty PQ\n";
  assert(!pq.empty());  
  cout << "\nIts size should now be 5. It is: " << pq.size() << endl;
  assert(5 == pq.size());  
  cout << "The front should be 20. It is: " << pq.front() << endl;
  assert(20 == pq.front()); 
  cout << "The back should be 10. It is: " << pq.back() << endl;
  assert(10 == pq.back());  
  
  //const copy constructor test
  {
    cout << "\nCreating const copy with copy constructor\n";
    const PriorityQueue<int> copy = pq;
    if(!copy.empty()) cout << "copy.empty() returned false that it was empty\n";
    else cout << "Error: copy.empty() returned true for a non-empty PQ\n";
    assert(!copy.empty());  
    cout << "Copy size should now be 5. It is: " << copy.size() << endl;
    assert(5 == copy.size());  
  }
  
  //operator= copy test
  {
    cout << "\nCreating copy with with operator=\n";
    PriorityQueue<int> copy;
    cout << "Should initially have size 0. It is: " << copy.size() << endl;
    assert(copy.empty());
    cout << "Assigning copy to = pq\n";
    copy = pq;
    if(!copy.empty()) cout << "copy.empty() returned false that it was empty\n";
    else cout << "Error: copy.empty() returned true for a non-empty copy\n";
    assert(!copy.empty());  
    cout << "Copy 2's size should now be 5. It is: " << copy.size() << endl;
    assert(5 == copy.size());  
    cout << "The front should be 20. It is: " << copy.front() << endl;
    assert(20 == copy.front()); 
    cout << "The back should be 10. It is: " << copy.back() << endl;
    assert(10 == copy.back());  
    cout << "Dequeuing the entire copy of pq: \n";
    for(; copy.size();)
      cout << copy.dequeue() << ' '; 
    cout << "\nCopy should now be size 0. It is: " << copy.size() << endl;
    assert(copy.empty());    
    if(copy.empty()) cout << "copy.empty() returned true that it was empty\n";
    else cout << "Error: copy.empty() returned false for an empty copy\n";
    assert(copy.empty()); 
  }
  
  temp = pq.dequeue();
  cout << "\nDequeuing root of pq. It should return 20. It is: " << temp << endl;
  assert(20 == temp);  
  
  cout << "\nIts size should now be 4. It is: " << pq.size() << endl;
  assert(4 == pq.size());    
  cout << "The front should be 13. It is: " << pq.front() << endl;
  assert(13 == pq.front());    
  cout << "The back should be 8. It is: " << pq.back() << endl;
  assert(8 == pq.back());    
  cout << "\nNow using clear to clear pq\n";
  
  pq.clear();
  cout << "Size should now be 0. It is: " << pq.size() << endl;
  assert(0 == pq.size());  
  if(pq.empty()) cout << "pq.empty() returned true that it was empty\n";
  else cout << "Error: pq.empty() returned false for empty PQ\n";
  assert(pq.empty());  
}
开发者ID:jchow751,项目名称:COMSC-210,代码行数:92,代码来源:PriorityQueueDriver.cpp

示例2: propagate

  void EstimatePropagator::propagate(OptimizableGraph::VertexSet& vset, 
      const EstimatePropagator::PropagateCost& cost, 
       const EstimatePropagator::PropagateAction& action,
       double maxDistance, 
       double maxEdgeCost)
  {
    reset();

    PriorityQueue frontier;
    for (OptimizableGraph::VertexSet::iterator vit=vset.begin(); vit!=vset.end(); ++vit){
      OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*vit);
      AdjacencyMap::iterator it = _adjacencyMap.find(v);
      assert(it != _adjacencyMap.end());
      it->second._distance = 0.;
      it->second._parent.clear();
      it->second._frontierLevel = 0;
      frontier.push(&it->second);
    }

    while(! frontier.empty()){
      AdjacencyMapEntry* entry = frontier.pop();
      OptimizableGraph::Vertex* u = entry->child();
      double uDistance = entry->distance();
      //cerr << "uDistance " << uDistance << endl;

      // initialize the vertex
      if (entry->_frontierLevel > 0) {
        action(entry->edge(), entry->parent(), u);
      }

      /* std::pair< OptimizableGraph::VertexSet::iterator, bool> insertResult = */ _visited.insert(u);
      OptimizableGraph::EdgeSet::iterator et = u->edges().begin();
      while (et != u->edges().end()){
        OptimizableGraph::Edge* edge = static_cast<OptimizableGraph::Edge*>(*et);
        ++et;

        int maxFrontier = -1;
        OptimizableGraph::VertexSet initializedVertices;
        for (size_t i = 0; i < edge->vertices().size(); ++i) {
          OptimizableGraph::Vertex* z = static_cast<OptimizableGraph::Vertex*>(edge->vertex(i));
          AdjacencyMap::iterator ot = _adjacencyMap.find(z);
          if (ot->second._distance != numeric_limits<double>::max()) {
            initializedVertices.insert(z);
            maxFrontier = (max)(maxFrontier, ot->second._frontierLevel);
          }
        }
        assert(maxFrontier >= 0);

        for (size_t i = 0; i < edge->vertices().size(); ++i) {
          OptimizableGraph::Vertex* z = static_cast<OptimizableGraph::Vertex*>(edge->vertex(i));
          if (z == u)
            continue;

          size_t wasInitialized = initializedVertices.erase(z);

          double edgeDistance = cost(edge, initializedVertices, z);
          if (edgeDistance > 0. && edgeDistance != std::numeric_limits<double>::max() && edgeDistance < maxEdgeCost) {
            double zDistance = uDistance + edgeDistance;
            //cerr << z->id() << " " << zDistance << endl;

            AdjacencyMap::iterator ot = _adjacencyMap.find(z);
            assert(ot!=_adjacencyMap.end());

            if (zDistance < ot->second.distance() && zDistance < maxDistance){
              //if (ot->second.inQueue)
                //cerr << "Updating" << endl;
              ot->second._distance = zDistance;
              ot->second._parent = initializedVertices;
              ot->second._edge = edge;
              ot->second._frontierLevel = maxFrontier + 1;
              frontier.push(&ot->second);
            }
          }

          if (wasInitialized > 0)
            initializedVertices.insert(z);

        }
      }
    }

    // writing debug information like cost for reaching each vertex and the parent used to initialize
#ifdef DEBUG_ESTIMATE_PROPAGATOR
    cerr << "Writing cost.dat" << endl;
    ofstream costStream("cost.dat");
    for (AdjacencyMap::const_iterator it = _adjacencyMap.begin(); it != _adjacencyMap.end(); ++it) {
      HyperGraph::Vertex* u = it->second.child();
      costStream << "vertex " << u->id() << "  cost " << it->second._distance << endl;
    }
    cerr << "Writing init.dat" << endl;
    ofstream initStream("init.dat");
    vector<AdjacencyMapEntry*> frontierLevels;
    for (AdjacencyMap::iterator it = _adjacencyMap.begin(); it != _adjacencyMap.end(); ++it) {
      if (it->second._frontierLevel > 0)
        frontierLevels.push_back(&it->second);
    }
    sort(frontierLevels.begin(), frontierLevels.end(), FrontierLevelCmp());
    for (vector<AdjacencyMapEntry*>::const_iterator it = frontierLevels.begin(); it != frontierLevels.end(); ++it) {
      AdjacencyMapEntry* entry       = *it;
      OptimizableGraph::Vertex* to   = entry->child();
//.........这里部分代码省略.........
开发者ID:Aerobota,项目名称:c2tam,代码行数:101,代码来源:estimate_propagator.cpp

示例3: emptyFrameQueue

	void emptyFrameQueue(){
		while(!frameQueue.empty()){
			frameQueue.pop();
		}
	}
开发者ID:SaferSocietyGroup,项目名称:videoplayer,代码行数:5,代码来源:Video.cpp


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