programming-examples/c++/Others/TestLeftistHeap.cpp - Test program for leftist heaps.cpp
2019-11-15 12:59:38 +01:00

35 lines
912 B
C++

TestLeftistHeap.cpp - Test program for leftist heaps
#include "LeftistHeap.h"
#include <iostream.h>
int main( )
{
int numItems = 10000;
LeftistHeap<int> h;
LeftistHeap<int> h1;
LeftistHeap<int> h2;
int i = 37;
for( i = 37; i != 0; i = ( i + 37 ) % numItems )
if( i % 2 == 0 )
h1.insert( i );
else
h.insert( i );
h.merge( h1 );
h2 = h;
for( i = 1; i < numItems; i++ )
{
int x;
h2.deleteMin( x );
if( x != i )
cout << "Oops! " << i << endl;
}
if( !h1.isEmpty( ) )
cout << "Oops! h1 should have been empty!" << endl;
return 0;
}