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


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

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


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

示例1: main

int main()
{
	
  try{
    int data, num;
    scanf("num:%d\n", &num);
				
    PriorityQueue q;
		
    while(scanf("%d\n", &data) != EOF){
      q.Enqueue(data);
    }
		
    while ( ! q.IsEmpty() )  {
      cout << q.Min() << endl;
      q.DequeueMin();
    }
		
  }catch(const char* str ){
    cout << str << endl;
  }
	
  return 0;
	
}
开发者ID:yoheiotake,项目名称:Algorithm2,代码行数:25,代码来源:linearpq.cpp

示例2: Simulation

//
//   This file contains the C++ code from Program 11.22 of
//   "Data Structures and Algorithms
//    with Object-Oriented Design Patterns in C++"
//   by Bruno R. Preiss.
//
//   Copyright (c) 1998 by Bruno R. Preiss, P.Eng.  All rights reserved.
//
//   http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/programs/pgm11_22.cpp
//
void Simulation (PriorityQueue& eventList, time timeLimit)
{
    bool serverBusy = false;
    unsigned int numberInQueue = 0;
    ExponentialRV serviceTime (100.);
    ExponentialRV interArrivalTime (100.);

    eventList.Enqueue (*new Event (Event::arrival, 0));
    while (!eventList.IsEmpty ())
    {
	Event& event =
	    dynamic_cast<Event&> (eventList.DequeueMin ());
	Event::Time& t = event.Key ();
	if (t > timeLimit)
	{
	    delete &event;
	    eventList.Purge ();
	    break;
	}
	switch (event.Value ())
	{
	case Event::arrival:
	    if (!serverBusy)
	    {
		serverBusy = true;
		eventList.Enqueue (*new Event (Event::departure,
		    t + serviceTime.Sample ()));
	    }
	    else
		++numberInQueue;
	    eventList.Enqueue (*new Event (Event::arrival,
		t + interArrivalTime.Sample ()));
	    break;
	case Event::departure:
	    if (numberInQueue == 0)
		serverBusy = false;
	    else
	    {
		--numberInQueue;
		eventList.Enqueue (*new Event (Event::departure,
		    t + serviceTime.Sample ()));
	    }
	    break;
	}
	delete &event;
    }
}
开发者ID:lbaby,项目名称:codeGarden,代码行数:57,代码来源:pgm11_22.cpp


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