本文整理汇总了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;
}
示例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;
}
}