Matthew wrote:I see you used by-reference in C++ there.
For passing class objects to class methods I typically do
Matthew wrote:Maybe you could do a binary search or did I miss that? The binary search algorithm could call the sorting algorithm to ensure the list is sorted.
The sort algorithm is used with iterators and therefore, would be difficult (if even possible at all) to implement. I've decided to use quicksort, but yet again, I am stuck. This is what I have so far:
Code: Select all
void sort()
{
int pivot = itsLength/2;
chamber <T> LESS;
chamber <T> GREAT;
std::cout << "\nAfter Declarations\n";
for (int i = 0; i < itsLength; i++)
{
if (pChamber[i] > pChamber[pivot] || pChamber[i] == pChamber[pivot])
GREAT.add_on(pChamber[i]);
else
LESS.add_on(pChamber[i]);
}
std::cout << "\nAfter for-loop\n";
while (GREAT.len() > 1 || LESS.len() > 1)
{
if (GREAT.len() > 1)
GREAT.sort();
if (LESS.len() > 1)
LESS.sort();
}
std::cout << "\nAfter while-loop\n";
if (GREAT.len() == 1 && LESS.len() == 1)
{
add_on(LESS);
add_on(GREAT);
}
std::cout << "\nAfter add_on(chamber)\n";
}
Now for the obvious question, do you have any suggestions to how I can get it to work?