Hello. I'm trying to write a heapsort for my class.
So far, I have a working templated Heap class. To this, I added two static methods:
static Heap BuildHeap(Type list[], int numItems)
{
Heap ret;
ret.size = numItems;
ret.capacity = numItems;
ret.array = list;
int index = ParentOf(ret.size - 1);
while (index >= 0)
{
ret.WalkDown(index);
index--;
}
}
static void Sort(Type list[], int numItems)
{
Heap<Type> heap;
heap = Heap.BuildHeap(list, numItems);
heap.Print();
// Remove max the items into order
}
The goal is to be able to call the Sort method as
Heap.Sort(array, sizeofArray)
to sort the list.
However, since Heap is a templated class, Sort incorporates the dynamic type Type, and gives me errors when trying to compile my main:
#include <iostream>
#include <stdlib.h>
#include "heapsort.h"
using namespace std;
int main()
{
int array[] = {11, 22, 43, 45, 33, 23, 43};
Heap.Sort<int>(array, 7);
}
Removing the <int> doesn't help any. However, if I comment out the call to Heap.Sort, it compiles just fine.
Anyhelp would be appreciated.