From 3cef0a39bc70308fd5a1fb3783c5f4ca716aca80 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 6 Dec 2009 09:32:19 +0000 Subject: I corrected a peculiar heap corner case that caused an infinite loop. --- src/heap.h | 2 ++ src/list.h | 4 ++-- src/tests/heap.cpp | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/heap.h b/src/heap.h index 523c8e2..60c39ac 100644 --- a/src/heap.h +++ b/src/heap.h @@ -95,6 +95,8 @@ namespace Bu for( int j = iFill; j >= 0; ) { int k = (j-1)/2; + if( j == k ) + break; if( cmp( aItem[k], aItem[j] ) ) break; diff --git a/src/list.h b/src/list.h index f76c505..2e6280c 100644 --- a/src/list.h +++ b/src/list.h @@ -240,7 +240,7 @@ namespace Bu return *this; } - bool operator==( const MyType &rhs ) + bool operator==( const MyType &rhs ) const { if( getSize() != rhs.getSize() ) return false; @@ -255,7 +255,7 @@ namespace Bu return true; } - bool operator!=( const MyType &rhs ) + bool operator!=( const MyType &rhs ) const { return !(*this == rhs); } diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp index b1f510a..9a2daf0 100644 --- a/src/tests/heap.cpp +++ b/src/tests/heap.cpp @@ -71,6 +71,8 @@ int main() Bu::Heap hStr; int j = 0; + hStr.enqueue("George"); + printHeap( hStr, j++ ); hStr.enqueue("George"); printHeap( hStr, j++ ); hStr.enqueue("Sam"); @@ -95,6 +97,7 @@ int main() Bu::List lStr; + lStr.insertSorted("George"); lStr.insertSorted("George"); lStr.insertSorted("Sam"); lStr.insertSorted("Abby"); -- cgit v1.2.3