本文整理汇总了C++中PriorityQueue::makeEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ PriorityQueue::makeEmpty方法的具体用法?C++ PriorityQueue::makeEmpty怎么用?C++ PriorityQueue::makeEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue::makeEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
// problem setup goes here
bool test1=true, test2=true;
PriorityQueue<double> pq;
int i, REPS = 1000000;
srand (time(NULL));
while(test1) // operator[] assignment at zeroth index, O(1)
{
cout << "\n Test 1 - enqueue, O(log n)\n\n";
// programmer customizations go here
double n = 500000; // THE STARTING PROBLEM SIZE
string bigOh = "O(log n)"; // YOUR PREDICTION: O(1), O(log n), O(n), O(n log n), or O(n squared)
int elapsedTimeTicksNorm;
double expectedTimeTicks, m;
for (int cycle=0; cycle<4; cycle++, n*=2)
{
// more problem setup goes here -- the stuff not timed
for(i=0; i<n; i++)
pq.enqueue(rand() % RAND_MAX);
long elapsedTimeTicks = 0;
for (i=0; i<REPS; i++)
{
m = rand() % RAND_MAX;
assert(pq.size()==n);
// initize the timer
clock_t startTime = clock();
// do something where n is the "size" of the problem
pq.enqueue(m);
// compute timing results
clock_t endTime = clock();
elapsedTimeTicks += (long)(endTime - startTime);
pq.dequeue(m);
}
double factor = pow(2.0, cycle);
if (cycle == 0)
elapsedTimeTicksNorm = elapsedTimeTicks;
else if (bigOh == "O(1)")
expectedTimeTicks = elapsedTimeTicksNorm;
else if (bigOh == "O(log n)")
expectedTimeTicks = log(double(n)) / log(n / factor) * elapsedTimeTicksNorm;
else if (bigOh == "O(n)")
expectedTimeTicks = factor * elapsedTimeTicksNorm;
else if (bigOh == "O(n log n)")
expectedTimeTicks = factor * log(double(n)) / log(n / factor) * elapsedTimeTicksNorm;
else if (bigOh == "O(n squared)")
expectedTimeTicks = factor * factor * elapsedTimeTicksNorm;
// reporting block
cout << elapsedTimeTicks;
if (cycle == 0) cout << " (expected " << bigOh << ')';
else cout << " (expected " << expectedTimeTicks << ')';
cout << " for n=" << n << endl;
pq.makeEmpty();
assert(pq.isEmpty());
}
test1=false;
}
REPS = 500000;
while(test2) // operator[] assignment at 100th index, O(1)
{
cout << "\n\n Test 2 - dequeue, O(log n)\n\n";
// programmer customizations go here
double n = 500000; // THE STARTING PROBLEM SIZE
string bigOh = "O(log n)"; // YOUR PREDICTION: O(1), O(log n), O(n), O(n log n), or O(n squared)
int elapsedTimeTicksNorm;
double expectedTimeTicks;
for (int cycle=0; cycle<4; cycle++, n*=2)
{
// more problem setup goes here -- the stuff not timed
for(i=0; i<n; i++)
pq.enqueue(rand() % RAND_MAX); // fill pq
long elapsedTimeTicks = 0;
clock_t startTime, endTime;
double j;
for (i=0; i<REPS; i++)
{
assert(pq.size()==n);
// initize the timer
startTime = clock();
// do something where n is the "size" of the problem
pq.dequeue(j);
// compute timing results
endTime = clock();
elapsedTimeTicks += (long)(endTime - startTime);
pq.enqueue(j);
//.........这里部分代码省略.........