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


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

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


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

示例1: main

int main()
{
    // push , pop , top test
    {
        PriorityQueue<int> p;
        assert(p.getSize() == 0);
        assert(p.getCapacity() == 21);

        p.push(3);p.push(2);p.push(7);p.push(11);p.push(23);
        p.pop();p.pop();
        p.push(3);p.push(2);p.push(43);p.push(21);p.push(25);
        p.pop();p.pop();
        vector<int> vcmp = {7, 11, 21, 23, 25, 43};

        assert(p.getSize() == 6);
        assert( vcmp == print_queue<int>(p));
        assert(p.getCapacity() == 21);

    }

    // size , capacity , clear , destroy test
    {
        PriorityQueue<int> p;
        assert(p.getSize() == 0);
        assert(p.getCapacity() == 21);

        for(auto i = 0; i<21; i++){
            p.push(i);
        }
        assert(p.getSize() == 21);
        assert(p.getCapacity() == 42);

        p.clear();
        assert(p.getSize() == 0);
        assert(p.getCapacity() == 42);

        p.destroy();
        assert(p.getSize() == 0);
        assert(p.getCapacity() == 0);
    }

    // heapsort test
    {
        vector<int> v = {1, 16, 12, 2, 25, 5, 6};
        vector<int> cmpv = {1, 2, 5, 6, 12, 16, 25};
        heap_sort(v.begin(), v.end());
        assert(v == cmpv);
        
    }


    cout<< "All TestCases Pass."<<endl;
    return 0;
}
开发者ID:arctanx0,项目名称:Swag-Libraries,代码行数:54,代码来源:heap.cpp

示例2: testThreadFill

void PriorityQueueTest::testThreadFill( void )
{
  CPPUNIT_ASSERT( _queue->empty() );

  ClassFuncThread<PriorityQueueTest> fillQueueThread( this, &PriorityQueueTest::fillQueue );
  CPPUNIT_ASSERT_NO_THROW( fillQueueThread.start() );

  for ( unsigned i = 0; i < FillSize; ++i ) {
    Dummy::Ptr d( _dummies->pop() );
    CPPUNIT_ASSERT( d );
    CPPUNIT_ASSERT( d->isValid() );

    Dummyer::Ptr d2( d );
    CPPUNIT_ASSERT( d2 );
    CPPUNIT_ASSERT( d2->isValid() );

    CPPUNIT_ASSERT( d->refs() );
    CPPUNIT_ASSERT_EQUAL( i, d->val() );
    d = 0;
    d2 = 0;
  }

  CPPUNIT_ASSERT_NO_THROW( fillQueueThread.join() );
  CPPUNIT_ASSERT( _queue->empty() );
}
开发者ID:CodeMonkeySteve,项目名称:libfinagle,代码行数:25,代码来源:PriorityQueueTest.cpp

示例3: testOrder

void PriorityQueueTest::testOrder( void )
{
  _queue->push( 5, 0.0 );
  _queue->push( 6, 0.0 );
  _queue->push( 3, 1.0 );
  _queue->push( 4, 1.0 );
  _queue->push( 1, 2.0 );
  _queue->push( 2, 2.0 );

  CPPUNIT_ASSERT_EQUAL( 1U, _queue->pop() );
  CPPUNIT_ASSERT_EQUAL( 2U, _queue->pop() );
  CPPUNIT_ASSERT_EQUAL( 3U, _queue->pop() );
  CPPUNIT_ASSERT_EQUAL( 4U, _queue->pop() );
  CPPUNIT_ASSERT_EQUAL( 5U, _queue->pop() );
  CPPUNIT_ASSERT_EQUAL( 6U, _queue->pop() );
}
开发者ID:CodeMonkeySteve,项目名称:libfinagle,代码行数:16,代码来源:PriorityQueueTest.cpp

示例4: uf

// @snip <sh19910711/contest:setlib/disjoints_set.cpp>
template <typename GraphType> const typename std::vector<typename GraphType::Edge> get_minimum_spanning_forest( const GraphType& G ) {
  typedef typename std::vector<typename GraphType::Edge> Edges;
  typedef typename GraphType::Edge GraphEdge;
  typedef typename GraphType::Edges GraphEdges;
  typedef std::priority_queue<GraphEdge, Edges, std::greater<GraphEdge> > PriorityQueue;
  typedef setlib::DisjointSets UnionFind;

  Edges res;
  PriorityQueue E;
  UnionFind uf(G.num_vertices);

  for ( int i = 0; i < G.num_vertices; ++ i ) {
    for ( typename GraphEdges::const_iterator it_i = G.vertex_edges[i].begin(); it_i != G.vertex_edges[i].end(); ++ it_i ) {
      const GraphEdge& e = **it_i;
      E.push(GraphEdge(e.from, e.to, e.weight));
    }
  }

  while ( ! E.empty() ) {
    GraphEdge e = E.top();
    E.pop();
    if ( ! uf.same(e.from, e.to) ) {
      res.push_back(e);
      uf.merge(e.from, e.to);
    }
  }

  return res;
}
开发者ID:sh19910711,项目名称:contest,代码行数:30,代码来源:get_minimum_spanning_forest.cpp

示例5: while

vector<T> print_queue(PriorityQueue<T> &q){
    vector<T> ret;
    while(!q.isEmpty()) {
        ret.push_back(q.getTop());
        q.pop();
    }
    return ret;
}
开发者ID:arctanx0,项目名称:Swag-Libraries,代码行数:8,代码来源:heap.cpp

示例6: squareQueue

void PriorityQueueTest::squareQueue( void )
{
  for ( unsigned i = 0; i < FillSize; ++i ) {
    unsigned v;
    CPPUNIT_ASSERT_NO_THROW( v = _queue->pop() );
    CPPUNIT_ASSERT_NO_THROW( _squared->push( sqr(v) ) );
  }
}
开发者ID:CodeMonkeySteve,项目名称:libfinagle,代码行数:8,代码来源:PriorityQueueTest.cpp

示例7: testPush

void PriorityQueueTest::testPush( void )
{
  CPPUNIT_ASSERT( _queue->empty() );
  CPPUNIT_ASSERT_NO_THROW( _queue->push( 42 ) );
  CPPUNIT_ASSERT_EQUAL( 1U, _queue->size() );
  CPPUNIT_ASSERT_EQUAL( 42U, _queue->pop() );
  CPPUNIT_ASSERT( _queue->empty() );
}
开发者ID:CodeMonkeySteve,项目名称:libfinagle,代码行数:8,代码来源:PriorityQueueTest.cpp

示例8: dumpContents

void dumpContents( const string & msg, PriorityQueue & pq )
{
    cout << msg << ":" << endl;
    while( !pq.empty( ) )
    {
        cout << pq.top( ) << endl;
        pq.pop( );
    }
}
开发者ID:FMsunyh,项目名称:Algorithm,代码行数:9,代码来源:TestPQ.cpp

示例9: main

int main(){
  PriorityQueue<int> pq;
  for(int i=0;i<10;i++){
    pq.push(i);
  }
  while(!pq.empty()){
    cout<<pq.top()<<" ";
    pq.pop();
  }
}
开发者ID:ccjeremiahlin,项目名称:CodingCheetSheet,代码行数:10,代码来源:priorityQueue.C

示例10: dijkstra

float* Dijkstra::dijkstra(Graph *&graph, int s)
{
	int n = graph->getVerticesNum();
	if ((s < 0)||(s >= n))
		return 0;
	int m = graph->getRealSize();
	
	Data** dist = new Data*[n];
	int* up = new int[n];

	for (int i = 0; i < n; i++){
		up[i] = 0;
		dist[i] = new DataFloat(i, FLT_MAX);
	}
	dist[s]->priority = 0;

	PriorityQueue *queue = new PriorityQueue(dist, n, 4);

	Edge** edges = graph->getEdgeSet();
	int edgeCount = m;
	while ((edgeCount != 0) && (!queue->isEmpty()))
	{
		Data* tmp = queue->pop();
		int v = ((DataFloat*)tmp)->v;
		int v0 = -1;
		float delta;
		for (int i = 0; i < m; i++)
		{
			v0 = -1;
			if (edges[i]->K == v)
				v0 = edges[i]->N;
			if (edges[i]->N == v)
				v0 = edges[i]->K;
			if (v0 == -1) continue;
			//edgeCount--;
			delta = dist[v0]->priorities - (dist[v]->priorities + graph->getWeight(v, v0));
			if (delta > 0){
				dist[v0]->priorities = graph->getWeight(v, v0) + dist[v]->priorities;
				up[v0] = v;
			}
		}
	}
	
	float *result = new float[n];
	for (int i = 0; i < n; i++)
		result[i] = dist[i]->priorities;

	for (int i = 0; i < n; i++)
		delete dist[i];
	delete []dist;
	delete queue;
	delete []up;

	return result;
}
开发者ID:Yaroslav-Lahtachev,项目名称:mp2-lab4,代码行数:55,代码来源:DijkstrasAlg.cpp

示例11: testSynchronize

void PriorityQueueTest::testSynchronize( void )
{
  ClassFuncThread<PriorityQueueTest> enqueueThread( this, &PriorityQueueTest::enqueue );
  CPPUNIT_ASSERT_NO_THROW( enqueueThread.start() );

  unsigned v;
  CPPUNIT_ASSERT_NO_THROW( v = _queue->pop() );
  CPPUNIT_ASSERT_EQUAL( 42U, v );

  CPPUNIT_ASSERT_NO_THROW( enqueueThread.join() );
  CPPUNIT_ASSERT( _queue->empty() );
}
开发者ID:CodeMonkeySteve,项目名称:libfinagle,代码行数:12,代码来源:PriorityQueueTest.cpp

示例12: main

int main()
{

  PriorityQueue* pq = new PriorityQueue;
  
  pq->push(7);
  pq->push(3);
  pq->push(10);
  pq->push(1);

   

  cout << pq->pop() << endl;
  cout << pq->pop() << endl;
  cout << pq->pop() << endl;
  cout << pq->pop() << endl;


  delete pq;   

  return 0;
}
开发者ID:rheno,项目名称:C,代码行数:22,代码来源:priority_queue.cpp

示例13: inpainting_loop

inline
void inpainting_loop(VertexListGraph& g, InpaintingVisitorType vis,
                      BoundaryStatusMap& boundaryStatusMap, PriorityQueue& boundaryNodeQueue,
                      NearestNeighborFinder find_inpainting_source, 
                      PatchInpainter inpaint_patch) 
{
  typedef typename boost::graph_traits<VertexListGraph>::vertex_descriptor Vertex;
  typedef typename boost::graph_traits<VertexListGraph>::edge_descriptor Edge;
  typedef typename boost::property_traits<PositionMap>::value_type PositionValueType;
  
  // When this function is called, the priority-queue should already be filled 
  // with all the hole-vertices (which should also have "Color::black()" color value).
  // So, the only thing this function does is run the inpainting loop. All of the
  // actual code is externalized in the functors and visitors (vis, find_inpainting_source, inpaint_patches, etc.).

  while(true) 
  {
    // find the next target to in-paint:
    Vertex targetNode;
    do
    {
      if( boundaryNodeQueue.empty() )
      {
        std::cout << "Queue is empty, exiting." << std::endl;
        return;  //terminate if the queue is empty.
      }
      targetNode = boundaryNodeQueue.top();
      boundaryNodeQueue.pop();
    } while( get(boundaryStatusMap, targetNode) == false );

    // Notify the visitor that we have a hole target center.
    vis.discover_vertex(targetNode, g);

    // next, we want to find a source patch-center that matches best to our target-patch:
    Vertex source_patch_center = find_inpainting_source(targetNode);
    vis.vertex_match_made(targetNode, source_patch_center, g);

    // finally, do the in-painting of the target patch from the source patch.
    //  the inpaint_patch functor should take care of iterating through the vertices in both
    //  patches and call "vis.paint_vertex(target, source, g)" on the individual vertices.
    inpaint_patch(targetNode, source_patch_center, g, vis);

    if(!vis.accept_painted_vertex(targetNode, g))
      {
      throw std::runtime_error("Vertex was not painted successfully!");
      }

    vis.finish_vertex(targetNode, g);
  } // end main iteration loop
  
};
开发者ID:daviddoria,项目名称:TempRepo,代码行数:51,代码来源:InpaintingAlgorithm.hpp

示例14: heap_sort

void heap_sort(T &begin, T &end) {
    PriorityQueue<int> p;
    T it = begin;
    while(it!=end) {
        p.push(*it);
        it++;
    }
    it = begin;
    while(it!=end) {
        *it = p.getTop();
        p.pop();
        it++;
    }
}
开发者ID:arctanx0,项目名称:Swag-Libraries,代码行数:14,代码来源:heap.cpp

示例15: getNode

	Node getNode(char name){
		if (find(name)){
			PriorityQueue tempQueue;
			while (top().name != name){
				tempQueue.push(top());
				pop();
			}
			Node node = top();
			while (!tempQueue.empty()){
				push(tempQueue.top());
				tempQueue.pop();
			}
			return node;
		}
	}
开发者ID:anthonycj04,项目名称:Prim-s-Algo,代码行数:15,代码来源:prims.cpp


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