aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/archetype/heap_sort.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/glk/archetype/heap_sort.cpp')
-rw-r--r--engines/glk/archetype/heap_sort.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/engines/glk/archetype/heap_sort.cpp b/engines/glk/archetype/heap_sort.cpp
index 98753ccc70..2f0edd27fb 100644
--- a/engines/glk/archetype/heap_sort.cpp
+++ b/engines/glk/archetype/heap_sort.cpp
@@ -46,7 +46,7 @@ static void heapup() {
Element temp;
L = H.size();
- while (L > 0) {
+ while (L > 1) {
if ((L % 2) == 0)
parent = L / 2;
else
@@ -73,17 +73,17 @@ static void heapdown() {
Element comparep;
Element temp;
- L = 0;
+ L = 1;
while (L < H.size()) {
lc = L * 2;
- if (lc >= H.size()) {
+ if (lc > H.size()) {
L = lc;
} else {
rc = lc + 1;
if (!access_xarray(H, lc, lcp, PEEK_ACCESS))
g_vm->writeln(CANT_PEEK);
- if (rc >= H.size()) {
+ if (rc > H.size()) {
compare = lc;
comparep = lcp;
} else {
@@ -106,7 +106,7 @@ static void heapdown() {
g_vm->writeln(CANT_POKE);
L = compare;
} else {
- L = H.size();
+ L = H.size() + 1;
}
}
}