Ta=record
I1: integer;
I2: integer;
end;
Var
A: array [0.. 10] of Ta.
//a in the data for the
0, 1258
2 102
1 99
0 2
.
On i2 to ascending i1 first, and then in ascending order
The result is: 0 2
0, 1258
1 99
2 102
.
Thank you very much
CodePudding user response:
Code, roughly as follows, you modify,
Procedure TForm1. Button1Click (Sender: TObject);
Var
I, j, N: integer;
The begin
//i1 Ascend
For I:=0 to Length (a) - 2 do
For j:=0 to Length (a) - 2 - I do
If a [j]. I1 & gt; + 1 a [j].journal of i1 then
The begin
N:=a [j]. I1;
A [j]. Journal of i1:=a [j + 1] i1.
+ 1 a [j].journal of i1:=N;
end;
//i2 Descend
For I:=0 to Length (a) - 2 do
For j:=0 to Length (a) - 2 - I do
If a [j]. Journal of i2 & lt; + 1 a [j].journal of i2 then
The begin
N:=a [j]. Journal of i2;
A [j]. Journal of i2:=a [j + 1] i2.
+ 1 a [j].journal of i2:=N;
end;
end;
CodePudding user response:
With bubble sort methodCodePudding user response:
To: feiba7288The result should be wrong, you will become
0 2
0, 99
1 102
.
Silly way is carried out while the second sort segments, such as single row 0, 1 single row, more a cycle
CodePudding user response:
TO Andwo, I just told him that a basic sorting method, as TO how the actual effect, he can change the code under the flexible,CodePudding user response:
To the building Lord, much experience under this algorithm, much practice To learn writing code is his own things,CodePudding user response:
More practice can learnCodePudding user response:
Procedure TForm1. Btn1Click (Sender: TObject);
Type
Ta=record
I1: integer;
I2: integer;
end;
Var
A: array [0.. 3] of Ta.
NTa, mTa: Ta;
I, j: integer;
StrTmp: string;
The begin
//initialize array content
NTa. I1:=0;
NTa. I2:=1258;
A [0] :=nTa;
NTa. I1:=2;
NTa. I2:=102;
A [1] :=nTa;
NTa. I1:=1;
NTa. I2:=99;
A [2] :=nTa;
NTa. I1:=0;
NTa. I2:=2;
A [3] :=nTa;
//an array to i1 ascending order
For I:=0 to high (a) do
The begin
NTa:=a [I];
For j:=I + 1 to high (a) do
The begin
The mTa:=a, [j].
If the mTa. I1 & lt; NTa. I1 then
The begin
A: [j]=nTa;
NTa:=the mTa;
end;
end;
A: [I]=nTa;
end;
//an array with i2 ascending order
For I:=0 to high (a) do
The begin
NTa:=a [I];
For j:=I + 1 to high (a) do
The begin
The mTa:=a, [j].
If the mTa. I2 & lt; NTa. I2 then
The begin
A: [j]=nTa;
NTa:=the mTa;
end;
end;
A: [I]=nTa;
end;
//print arrangement results
StrTmp:=';
For I:=0 to high (a) do
The begin
Showmessage (inttostr (I));
StrTmp:=strTmp + inttostr (a [I]. I1) + ', '+ inttostr (a [I] i2) + CRH (13);
end;
Showmessage (strTmp);
end;
CodePudding user response:
An array with i2 ascending order, determine the i1 is the same, the same should be replacedCodePudding user response: