/********************************************************************************************
ezw2wBub.cpp
Jim Millard
for CO311
EZwindows sort visualization for two-way Bubble Sort
********************************************************************************************/
#include "ezw2wBub.h"
#include "ezwSwap.h"
#include "ezwUtils.h"
void TwoWayBubbleSort(SimpleWindow& W, RaySegment* ptrR[], int A[], const int size, const short load)
{
int begin = 0, end = size-1, current;
bool DoneSorting;
do {
DoneSorting = true;
for (current = begin; current < end; current++)
if (A[current] > A[current+1])
{
DoneSorting = false;
Swap(A[current+1],A[current]);
Swap(W, *ptrR[current+1], *ptrR[current], load);
}
Highlight(*ptrR[end], Green);
end--;
if (!DoneSorting)
for (current = end; current > begin; current--)
if (A[current] < A[current-1])
{
DoneSorting = false;
Swap(A[current],A[current-1]);
Swap(W, *ptrR[current], *ptrR[current-1], load);
}
Highlight(*ptrR[begin],Green);
begin++;
}
while (!DoneSorting);
}