summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Year_2/Algorithms/heapsort.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/Year_2/Algorithms/heapsort.cc b/Year_2/Algorithms/heapsort.cc
index 1709be5..d5108aa 100644
--- a/Year_2/Algorithms/heapsort.cc
+++ b/Year_2/Algorithms/heapsort.cc
@@ -35,9 +35,9 @@ public:
int r = right(i);
int max = i;
- if (l <= heapsize_ && !compare(l, i))
+ if (l <= heapsize_ && compare(l, max))
max = l;
- if (r <= heapsize_ && !compare(r, max))
+ if (r <= heapsize_ && compare(r, max))
max = r;
if (max != i) {
@@ -102,10 +102,11 @@ private:
int heapsize_ { 0 };
int n_;
HeapType type_;
- int
+
+ bool
compare(int i, int j)
{
- return (type_ == HeapType::Min) ? a_[i] < a_[j] : a_[j] > a_[i];
+ return (type_ == HeapType::Max) ? a_[i] > a_[j] : a_[j] > a_[i];
}
int count_ { 0 };
};