#include "QuickSort3.h"
QuickSort3::QuickSort3(int n, int* x) : QuickSort(n, x) {
this->algName = "Quick Sort [Left] optimized";
}
void QuickSort3::Run(void)
{
this->Launch(0, (this->n - 1));
}
void QuickSort3::Launch(int l, int u) {
if (l >= u)
return;
int t, tmp;
int i,j;
t = this->x[l]; i = l; j = u+1;
while (1) {
/* пропуск элементов справа и слева,
чтобы не делать лишней работы */
do i++; while (i <= u && this->x[i] < t);
do j--; while (this->x[j] > t);
if (i > j)
break;
// Делаем swap(i, j):
tmp = this->x[i]; this->x[i] = this->x[j]; this->x[j] = tmp;
this->CountSwap();
}
// swap(l, j)
tmp = this->x[l]; this->x[l] = this->x[j]; this->x[j] = tmp;
this->CountSwap();
this->Launch(l, j-1);
this->Launch(j+1, u);
}
QuickSort3::~QuickSort3(void)
{
}