Array bubble sort test case error

#include
using namespace std;
void re(int arr[], int n)
{
int key, j,z=0,i;
if(arr[0]<0)
z++;
for (i = 1; i < n; i++)
{
key = arr[i];
if (key >= 0)
{
continue;
}
z++;
j = i - 1;
while (j >= 0 && arr[j] >= 0)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}

   for(i=0;i<z;i++)
{
    arr[i]=-arr[i];
}
for(i=0;i<z-1;i++)
{
    for(j=0;j<z-i-1;j++)
    {
        if(arr[j]<arr[j+1])
            swap(arr[j],arr[j+1]);
    }
}
for(i=0;i<z;i++)
{
    arr[i]=-arr[i];
}
for(i=z;i<n;i++)
{
    for(j=z;j<n;j++)
    {
        if(arr[j]>arr[j+1])
            swap(arr[j],arr[j+1]);
    }
}
for(i=0;i<n;i++)
{
    cout<<arr[i]<<endl;
}

}
int main()
{
int n;
cin>>n;
int arr[n],i;
for(i=0;i<n;i++)
{
cin>>arr[i];
}
re(arr,n);

}

@Shivam31 hey shivam take this case
3
0
5
3
your code is giving
0
0
3
but it should be
0
3
5

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.