bubble sorting a dynamic array using only pointers

I am trying to bubble sort my dynamic array using the pointer. The following code sorts the array but replaces my largest number with 0. I have been unable to remedy this problem on my own. Any help would be appreciated.


void sortarray(int s, int* p)
{
int flag=1;
int pass = 1;
int temp;

while (flag)
{
flag = 0;
for(int i=0;i<=s-pass;i++)
{
if(*(p+i)>*(p+i+1))
{
temp = *(p+i);
*(p+i) = *(p+i+1);
*(p+i+1)=temp;
flag = 1;
}

}
pass++;

}
Last edited on
Topic archived. No new replies allowed.