Home > Back-end >  Novice for help, help you a great god
Novice for help, help you a great god

Time:10-18

A
# include
using namespace std;
Void swap (int & amp; X, int & amp; Y)
{int mid;
Mid=x; X=y; Y=mid; }

Void sequence (int * b, int left, int right) {
For (int j=1; J<=right - left; J++) {
For (int I=left; iIf (b [I] & gt; B) [I + 1] {
Swap (b [I], [I b + 1)); }
}
}
}

Int check (int * a, int left, int right, int x) {
Int min_index=left;
For (int I=left; i<=right; I++)
{int min_difference=100;
If ((a [I] & gt; X) & amp; & ((a [I] - x) & lt; Min_difference)) {
Min_index=I; }
}
Return min_index;
}


Void next_array (int * a, int n) {
Int length=n;
While (a/n - 1] {n=n - 1; }
Int min=check (, a, n - 1, length - 1 a [n - 2));
Swap (a/n - 2], a [min]);
Sequence (a, n - 1, length - 1);
for(int i=0; icoutcout}
Int jiecheng (int y) {
Int ans=1;
for(int i=1; i<=y; Ans i++) *=I;
Return ans.
}


Int main () {
Int x;
cin> x;
Int * p=new int [x];
for(int i=1; i<=x; I++) {
P/I - 1]=I; }
for(int j=0; Jcout

coutFor (int k=1; KNext_array (p, x);

return 0;
}

Himself wrote a whole dictionary order, don't know what went wrong, output is only a part of the whole arrangement,

2
# include
using namespace std;
Void swap (int & amp; X, int & amp; Y)
{int mid;
Mid=x; X=y; Y=mid; }

Void quicksort (int * a, int left, int right) {
Int key=a, [left].
Int I=left; Int j=right;
While (I! J)={
While (a [j] & gt; Key) {
j--; }
Swap (a [j], a [I]);
While (a [I] i++; }
Swap (a [j], a [I]);
}
Quicksort (a, left, I - 1); Quicksort (a, I + 1, right);
}

Int main () {
int length;
cin> Length;
Int * p=new int (length),
for(int i=0; icin> P [I]; }
Quicksort (p, 0, length - 1);
for(int j=0; Jcout

return 0;
}
Quick sort, and output the result, don't know where there is a problem,


  • Related