#include
#include
Int a, [100000].
Void QuickSort (int a [], int p, int r);
Int Partition (int a [], int p, int r);
Void Swap (int a [], int, int j);
Int main () {
Int N, m, I;
The scanf (" % d ", & amp; N);
for(i=0; I
A [I]=m;
}
A, QuickSort (0, N - 1);
for(i=0; I
printf("\n");
return 0;
}
Void swep (int a [], int, int j) {
Int temp=a [I];
A [I]=a, [j].
A [j]=temp;
}
Int Partition (int a [], int p, int r) {
Int I=p;
Int j=r + 1;
Int key=a, [p].
While (1) {
While (a [-] j & gt; The key & amp; & I & lt; R);
While (a [+ + I]
break;
Swep (a, I, j);
}
A [p]=a, [j].
A [j]=key;
Return j;
}
Void QuickSort (int a [], int p, int r) {
If (p
QuickSort (a, p, pos - 1);
QuickSort (a, pos + 1, r);
}
}
CodePudding user response:
Int a, [100000].This array defines whether a bit big, try get smaller
CodePudding user response:
But the topic request n< array element number; 100000CodePudding user response:
While (a [-] j & gt; The key & amp; & I & lt; R);//@ 1While (a [+ + I]
Change
While (a [-] j & gt; Key) {if (j==p) break; }
While (a [+ + I]
=========
@ 1 first, two wrong: to analyze the following
1. Because is for j, the decrement, you cross the border to prevent j, this is not a judgment I & lt; R, should be more than p, I cannot be more than the left boundary
2. Even to this while (a [-] j & gt; The key & amp; & J & gt;=p; Like this? Do you think OK?
Still have problem, assuming j==p, while at this time will continue to go once, walked to the front half, the next whlie conditions (a [-] j & gt; The key), j and crossing the line
Then change to the while (a [-] j & gt; The key & amp; & J & gt; P); How to? OK,