This method freezes the editor. Maybe it’s overload of stack. But I tested the function on 10 elements.
void ASortingAlgorithms::_QuickSortRecursion(TArray<int32>& Arr, int32 firstIndex, int32 lastIndex)
{
int32 index1 = firstIndex, index2 = lastIndex;
int32 Middle = Arr(firstIndex + lastIndex) / 2];
do
{
while (Arr[index1] < Middle) index1++;
while (Arr[index2] > Middle) index2--;
if (index1 <= index2)
{ Arr.Swap(index1, index2);}
} while (index1 <= index2);
if (index2 > 0) _QuickSortRecursion(Arr, firstIndex, index2);
if (lastIndex > index1) _QuickSortRecursion(Arr, index1, lastIndex);
}
The Editor freezes only if I use 2 lines at a time:
if (index2 > 0) _QuickSortRecursion(Arr, firstIndex, index2);
if (lastIndex > index1) _QuickSortRecursion(Arr, index1, lastIndex);
If I use one of these lines than the editor doesn’t freeze.
Tell me please why the editor freezes?