I understand that the following problem refers to the data sorting solution using a Quicksort or at least that is supposed to be, and I have been asked to find the error by which the program gets stuck, but no matter how much I searched I find it, supposedly the error is in the void QT
/ Update /
I made the debugger, with the modifications that I mention right away and the result it gives me is not what I expected, I do not know if it is a code error or if I really do not find how to fix the error ...
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int d(int A[], int b, int z)//Arreglo, izquierda, derecha
{
int l,r,p,t;
p=A[b];//Pivote igual a posición del arreglo
l=b;//l igual a izquierda (0)
r=z;//r igual a la derecha (9)
while (l<r)//Mientras izquierda (0) sea menor a (9)
{
while(A[r]>p)//Mientras posición r del arreglo (9) sea mayor a 0
r--;
while (l<r && A[l]<=p)
l++;
if(l<r)//Si izquierda menor que derecba
{
t=A[r];//T igual a arreglo posición r
A[l]=A[r];//Arreglo posición izquierda igual a arreglo derecha
A[r]=t;//Arreglo drecha igual a t
}
}
t=A[r];
A[r]=A[b];
A[b]=t;
return r;
}
void QT(int A[],int b,int z)//b izquierda y z derecha
{
int p;
if (b<z||b>=z)//-----Cambio
p=d(A,b,z);
if (b<z)//--Agregué esta condicion para poder dar fin a la función QT
QT(A,b,p-1);
if (b>z)//--Agregué para dar salida a la siguiente QT
QT(A,p+1,z);//----No se implementa
}
int main()
{
int Arr[3]={2,3,1};
int i;
printf("ANTES DE QS:");
for(i=0;i<3;i++)//----Cambio
printf("%i,",Arr[i]);
printf("\n \n");
QT (Arr,0,2);//-----Cambio
printf("DESPUES DE QS:");
for(i=0;i<3;i++)//-----Cambio
printf("%i,",Arr[i]);//Imprime 1,1,2 ni idea por que
return 0;
}