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


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

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


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

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

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

示例3: tick

	void tick(bool includeOldAudio = false){
		bool success = false;

		StreamFrameMap streamFrames;

		streamFrames[videoStream] = Frame::CreateEmpty();
		streamFrames[audioStream] = Frame::CreateEmpty();

		while(!IsEof() && !success)
		{
			try
			{
				int audioQueueTargetSize = audioDevice->GetBlockSize() * 4;

				while(
					frameQueue.size() < (unsigned int)targetFrameQueueSize || 
					(hasAudioStream() && audioHandler->getAudioQueueSize() < audioQueueTargetSize))
				{
					if(frameQueue.size() >= (unsigned int)maxFrameQueueSize)
						break;
					
					bool frameDecoded = decodeFrame(streamFrames);

					if(!frameDecoded)
						throw VideoException(VideoException::EDecodingVideo);

					if(streamFrames[videoStream]->finished != 0){
						frameQueue.push(streamFrames[videoStream]->Clone());
						streamFrames[videoStream] = Frame::CreateEmpty();
					}
					
					if(streamFrames[audioStream]->finished != 0){
						// only enqueue audio that's newer than the current video time, 
						// eg. on seeking we might encounter audio that's older than the frames in the frame queue.
						if(streamFrames[audioStream]->GetSamples().size() > 0 && 
							(includeOldAudio || streamFrames[audioStream]->GetSamples()[0].ts >= timeHandler->GetTime()))
						{
							audioHandler->EnqueueAudio(streamFrames[audioStream]->GetSamples());
						}else{
							FlogD("skipping old audio samples: " << streamFrames[audioStream]->GetSamples().size());
						}
						streamFrames[audioStream] = Frame::CreateEmpty();
					}
				}

				// sync framequeue target size with number of frames needed for audio queue 
				if(targetFrameQueueSize < (int)frameQueue.size()){
					targetFrameQueueSize = std::max((int)frameQueue.size(), minFrameQueueSize);
				}
					
				success = true;
			}

			catch(VideoException e)
			{
				Retry(Str("Exception in tick: " << e.what()));
			}
		}
	}
开发者ID:SaferSocietyGroup,项目名称:videoplayer,代码行数:59,代码来源:Video.cpp

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

示例5: fillQueue

void PriorityQueueTest::fillQueue( void )
{
  for ( unsigned i = 0; i < FillSize; ++i ) {
    Dummyer::Ptr d( new Dummyer(i) );
    _dummies->push( Dummy::Ptr(d) );
    d = 0;
  }
}
开发者ID:CodeMonkeySteve,项目名称:libfinagle,代码行数:8,代码来源:PriorityQueueTest.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: A_star

static bool A_star(DGR& dg, Weight& w, Digraph::Node s, Digraph::Node t, int k, DistMap& dist, PredMap& pred)
{
    if(s == t) return false;

	typedef QNode Node;
    typedef std::vector<QNode> NodeCon;
    typedef std::priority_queue<Node,NodeCon> PriorityQueue;
    PriorityQueue pq;

    int cnt = 0;
    pred[s] = INVALID;
	pq.push(Node(s, INVALID, 0, dist[s]));
    while(!pq.empty())
    {
		Node node = pq.top();
		Digraph::Node u = node.u;
		pred[u] = node.parent;
		//cout<<"->pop:f("<<Digraph::id(u)<<")="<<node.g+p.h
		//	  <<"\tg("<<Digraph::id(u)<<")="<<node.g
		//	  <<"\th("<<Digraph::id(u)<<")="<<node.h
		//	  <<endl;
        pq.pop();
        if(u == t)
        {
			//cout<<"---------------------"<<endl;
            cnt++;
        }
        if(cnt == k)
        {
            break;
        }
        for(typename DGR::OutArcIt e(dg,u);e!=INVALID;++e)
        {
            Digraph::Node v = dg.target(e);
            pred[v] = u;
			Node child_node(v, u, node.g + w[e], dist[v]);
			//cout<<"\t->push:f("<<Digraph::id(v)<<")="<<child_node.g+child_node.h
				//<<"\tg("<<Digraph::id(v)<<")="<<child_node.g
				//<<"\th("<<Digraph::id(v)<<")="<<child_node.h
				//<<endl;
			pq.push(child_node);
        }
    }
    return (cnt == k);
}
开发者ID:wyrover,项目名称:GDES,代码行数:45,代码来源:MaxResistancePath.cpp

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

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

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

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

示例12: testPushPop

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

  for ( unsigned i = 0; i < FillSize; ++i ) {
    CPPUNIT_ASSERT_EQUAL( i, _queue->size() );
    CPPUNIT_ASSERT_NO_THROW( _queue->push( i ) );
    CPPUNIT_ASSERT_EQUAL( i + 1, _queue->size() );
  }

  for ( unsigned i = FillSize; i > 0; --i ) {
    CPPUNIT_ASSERT_EQUAL( i, _queue->size() );
    CPPUNIT_ASSERT_EQUAL( FillSize - i, _queue->pop() );
    CPPUNIT_ASSERT_EQUAL( i - 1, _queue->size() );
  }

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

示例13:

	void													myerase(Node val)
	{
		PriorityQueue <Node, std::vector<Node>, Compare>	tmp;

		while (this->c.size() > 0)
		{
			auto											first = this->c.begin();
			if (first->getTab() == val.getTab())
			{
				this->pop();
				break;
			}
			tmp.push(*first);
			this->pop();
		}
		while (tmp.size() > 0)
		{
			this->push(tmp.top());
			tmp.pop();
		}
	}
开发者ID:Hhasni,项目名称:Npuzzle,代码行数:21,代码来源:PriorityQueue.hpp

示例14: decreaseKey

	void decreaseKey(char node, int newKey, char newPi){
		cout << "decreaseKey(" << node << ", " << newKey << ", " << newPi << endl;
		if (find(node)){
			cout << "found" << endl;
			PriorityQueue tempQueue;
			while (top().name != node){
				cout << "popping out" << endl;
				tempQueue.push(top());
				pop();
			}
			Node node = top();
			cout << "orig: " << node.name << ", " << node.pi << ", " << node.key << endl;
			pop();
			node.key = newKey;
			node.pi = newPi;
			push(node);
			while (!tempQueue.empty()){
				cout << "pushing back" << endl;
				push(tempQueue.top());
				tempQueue.pop();
			}
		}
		cout << "leaving" << endl;
	}
开发者ID:anthonycj04,项目名称:Prim-s-Algo,代码行数:24,代码来源:prims.cpp

示例15: while

//- "k_nearest_neighbor"
//- Find the K nearest neighbors to a point.
//-
//- Description:
//-   This algorithm is based on the best-first search.  The goal of this
//-   algorithm is to minimize the number of nodes visited by using the
//-   distance to each subtree's bounding box to avoid visiting subtrees
//-   which could not possibly contain one of the k nearest objects.
//-
template <class Z> CubitStatus KDDTree<Z>::k_nearest_neighbor
  (CubitVector &q, int k, double &closest_dist, DLIList<Z> &nearest_neighbors,
   typename KDDTree<Z>::DistSqFunc dist_sq_point_data
  )  
{
  //// Create the priority queues
  PriorityQueue<KDDTreeNode<Z>*> *queue = new PriorityQueue<KDDTreeNode<Z>*> (KDDTree<Z>::less_than_func);
  PriorityQueue<KDDTreeNode<Z>*> *queueTemp = new PriorityQueue<KDDTreeNode<Z>*> (KDDTree<Z>::less_than_func);


  KDDTreeNode<Z> *element = root;

  // push this node on the queue
  element->set_dist (min_dist_sq (q, element->safetyBox));
  element->set_dist_data (DD_SAFETY);
  queue->push (element);
  

  // if the k closest nodes on the tree are not leaf-nodes, expand the closest
  //   non-leaf node
  while ( !queue->empty() )
  {
    element = queue->top();
    queue->pop();

    if (element->get_dist_data() == DD_LEAF)
    {
      // this node is a leaf, so it can be pushed onto the temporary queue
      queueTemp->push (element);
    }
    else
    {
      // one of the top k nodes is a non-leaf node, so expand it
      if (element->left)
      {
        element->left->set_dist (min_dist_sq (q, element->left->safetyBox));
        element->left->set_dist_data (DD_SAFETY);
        queue->push (element->left);
      }
      if (element->right)
      {
        element->right->set_dist (min_dist_sq (q, element->right->safetyBox));
        element->right->set_dist_data (DD_SAFETY);
        queue->push (element->right);
      }
      element->set_dist (dist_sq_point_data (q, element->data));
      element->set_dist_data (DD_LEAF);
      queue->push (element);

      // take all the elements in the temporary queue and reinsert them into
      //   the actual queue
      while ( !queueTemp->empty() )
      {
        queue->push ( queueTemp->top() );
        queueTemp->pop ();
      }
    }

    if (queueTemp->size() == k)
    {
      // success-- place the k nodes into the nearest_neighbors list
      element = queueTemp->top();
      queueTemp->pop();
      closest_dist = element->get_dist();
      nearest_neighbors.append (element->data);

      while ( !queueTemp->empty() )
      {
        nearest_neighbors.append ( queueTemp->top()->data );
        queueTemp->pop();
      }
     
      return CUBIT_SUCCESS;
    }
  }
  return CUBIT_FAILURE;
}
开发者ID:tenpercent,项目名称:cp-sandbox,代码行数:86,代码来源:KDDTree.cpp


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