Код: Выделить всё
int shag=1;
void quickSort(int arr[], int left, int right, char v) {
cout <<"--------" <<shag <<"-------" <<endl;
if(v=='a') {cout <<" Вариант №1" <<endl; shag++;}
else {cout <<" Вариант №2" <<endl; shag++;}
cout <<" left: " <<left <<endl;
cout <<" right: " <<right <<endl;
int i = left, j = right;
int tmp;
int pivot = arr[(left + right) / 2];
cout <<endl <<"pivot: " <<pivot <<' ' <<endl;
while (i <= j) {
while (arr[i] < pivot)
i++;
while (arr[j] > pivot)
j--;
if (i <= j) {
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
cout <<" a[i]: " <<arr[i] <<endl;
cout <<" a[j]: " <<arr[j] <<endl;
}
};
cout <<"j: " <<j <<' ' <<endl;
cout <<"i: " <<i <<' ' <<endl;
if (left < j)
quickSort(arr, left, j, 'a');
if (i < right)
quickSort(arr, i, right , 'b');
}
int main()
{
int z[]={1, 2, 3, 5, 7, 7, 12, 26, 14};
quickSort(z,0,8,'a');
}
1) на 3 шаге получаются значения: j=-1 и i=1. Условия
Код: Выделить всё
left<j
Код: Выделить всё
i<right
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
На вопрос мне ответили. Функция на 4 шаге была вызвана из второго, на 5 из первого и на 6 из второго.
Тему можно закрыть...