diff options
Diffstat (limited to 'src/tests/heap.cpp')
| -rw-r--r-- | src/tests/heap.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp index 3217715..e35ea2a 100644 --- a/src/tests/heap.cpp +++ b/src/tests/heap.cpp | |||
| @@ -3,26 +3,49 @@ | |||
| 3 | 3 | ||
| 4 | #include "bu/heap.h" | 4 | #include "bu/heap.h" |
| 5 | 5 | ||
| 6 | typedef struct num | ||
| 7 | { | ||
| 8 | num( int iNum, int iOrder ) : iNum( iNum ), iOrder( iOrder ) | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | num( const num &src ) : iNum( src.iNum ), iOrder( src.iOrder ) | ||
| 13 | { | ||
| 14 | } | ||
| 15 | |||
| 16 | int iNum; | ||
| 17 | int iOrder; | ||
| 18 | |||
| 19 | bool operator<( const num &oth ) const | ||
| 20 | { | ||
| 21 | if( iNum == oth.iNum ) | ||
| 22 | return iOrder < oth.iOrder; | ||
| 23 | return iNum < oth.iNum; | ||
| 24 | } | ||
| 25 | bool operator>( const num &oth ) const | ||
| 26 | { | ||
| 27 | return iNum > oth.iNum; | ||
| 28 | } | ||
| 29 | } num; | ||
| 30 | |||
| 6 | int main() | 31 | int main() |
| 7 | { | 32 | { |
| 8 | Bu::Heap<int, Bu::__basicGTCmp<int> > hInt; | 33 | Bu::Heap<num> hNum; |
| 9 | 34 | ||
| 10 | for( int j = 0; j < 15; j++ ) | 35 | for( int j = 0; j < 30; j++ ) |
| 11 | { | 36 | { |
| 12 | int r = rand()%10; | 37 | int r = rand()%10; |
| 13 | printf("Pushing: %d, top: ", r ); | 38 | printf("Pushing: %d, top: ", r ); |
| 14 | hInt.push( r ); | 39 | hNum.enqueue( num( r, j ) ); |
| 15 | printf("%d\n", hInt.peek() ); | 40 | printf("%d\n", hNum.peek().iNum ); |
| 16 | } | 41 | } |
| 17 | 42 | ||
| 18 | for( int j = 0; j < 15; j++ ) | 43 | while( !hNum.isEmpty() ) |
| 19 | { | 44 | { |
| 20 | printf("%d ", hInt.peek() ); | 45 | printf("(%d:%d) ", hNum.peek().iOrder, hNum.peek().iNum ); |
| 21 | hInt.pop(); | 46 | hNum.dequeue(); |
| 22 | } | 47 | } |
| 23 | printf("\n"); | 48 | printf("\n"); |
| 24 | |||
| 25 | // hInt.print(); | ||
| 26 | 49 | ||
| 27 | return 0; | 50 | return 0; |
| 28 | } | 51 | } |
