I have an abstract base class (Comparable) with Date and Time virtually inheriting from it and a DateTime class v-inheriting from Date and Time.
My problem is this: I was tasked with dynamically allocating an array of Comparables.
Comparable ** compArray;
compArray = new Comparable *[n]; // where n is user specified number of elements
I then populate the array with DateTimes in alternating order. I need to sort this array using a quicksort and bubblesort combination. Bubble if length < 8. Comparable** from and Comparable ** to are the only parameters I'm allowed to use.
But I'm completely stuck. At this point it isn't worth pasting in the code I have due to it's frantic haphazardness.
Any help would be greatly appreciated. I've spent the past few hours trying to finish this up, only have sorting left in my project. Which is due tomorrow late morning.
Thanks in advance, Joel
EDIT:
void Sort(Comparable** a);
void quicksort(Comparable** from, Comparable** to);
Comparable** partition(Comparable** from, Comparable** to);
void Swap(Comparable** from, Comparable** to);
void safeRead(istream& sin, Comparable* d, const char* prompt);
void printArray(ostream & sout, Comparable **a, int size);
I was given the above to use as my arraySort.h
I'm using: int aSize = _msize(a) / sizeof(Comparable) - 1;
as my length variable... which I have to calculate instead of passing it, which is kind of annoying.
I'm mainly just having headaches over dereferencing the ** and calling it's lessThan or equals method in quicksort. Once I understand how to do a quicksort with it'll 'click' and I'll be able to easily to bubble sort.
EDIT: I currently have the following as my bubble sort, it doesn't sort the array at all.
void Swap(Comparable** from, Comparable** to)
{
Comparable** tmp;
tmp = from;
**from = **to;
to = tmp;
}
void bubbleSort(Comparable** a, int size)
{
int i, j;
for (i=0; i<size-1; i++)
{
for (j= size - 1; j > i; j--)
if(a[j]->lessThan(*a[j-1]))
Swap(&a[j], &a[j-1]);
}
}