Home > Back-end >  I ask why bosses the position error??
I ask why bosses the position error??

Time:12-18

# define _CRT_SECURE_NO_WARNINGS
#include
Void reverse (int [p], int left, int right)//data reverse order
{
int temp;
While (left & lt; Right)
{
Temp=p [left];
P=[left] p [right].
P [right]=temp;
Right++; Left++;
}
}
Void sort1 (int [p], int left, int right)//will be a set of is... The positive and negative... Negative transposition in order
{
int i=0;
The reverse (* p, left, right);
While (p [i++] <{0); }
Reverse (* p, left, I - 2);
Reverse (* p, I - 1, right);
}
Void CompletelySort (int * p, int left, int right)//the whole array is negative in the former, a positive number in the back and don't change the order of the original array
{
Int I=0, j=0;
While (left & lt; Right)
{
While (p [left++] & gt; {0); }
Left=left - 1;
J +=left;
While (p [j++] <{0); }
Reverse (* p, left, j - 2);
}
}
The main ()
{
Int a []={1, 2, 3, 4, 6, 7, 9, and 10,7,22, - 78};
Int right=sizeof (a)/sizeof (int) - 1;
For (int I=0; i {
Printf (" % d ", a [I]);
}
CompletelySort (a, 0, right);
For (int I=0; i {
Printf (" \ n % d ", a [I]);
}
}



CodePudding user response:

Many problems may sneak a look at the code, the feeling is
Reverse function while loop should be right -, left++, otherwise we are dead cycle
Reverse function call reverse function places (* p, left, right) to reverse (p, left, right), pay attention to the difference parameters * p and p
One did not scan the left

CodePudding user response:

Right -; Left++;
  • Related