Urgent: after sorting array 1-> array 2, evaluate the algorithm! 3Q Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiBase/html/delphi_20061215205531143.html
Sort array 1 and save the sequence number values before array 1 to array 2 in the order of sorting. This is a simple algorithm (with less code and second speed)
Example:
A [0] = 4
A [1] = 5
A [2] = 3...
A [1] maximum, A [0] Second, A [2] third
Take the original sequence number of A-> B
B [0] = 1
B [1] = 0
B [2] = 2...
3q ~
Online and other ing ~
What do you mean?
If it is just sorting, There Is A Sorting Algorithm in the DEMO about the thread that comes with DELPHI.
... Is
A [0] = 4
A [1] = 5
A [2] = 3...
Visible:
A [1] is the largest. Its serial number is I = 1 of A [I ].
A [0] Second, its serial number A [I] I = 0
A [2] 3. Its serial number is I = 2 of A [I]
Therefore:
Required:
B [0] = 1
B [1] = 0
B [2] = 2...
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
Ttest = record
Data: Integer;
Index: Integer;
End;
TForm1 = class (TForm)
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
Procedure Button1Click (Sender: TObject );
Private
{Private declarations}
Public
{Public declarations}
End;
Var
Form1: TForm1;
Implementation
{$ R *. dfm}
Procedure TForm1.Button1Click (Sender: TObject );
Var
FArray: array [0 .. 5] of Ttest;
I, j: integer;
T: Ttest;
Begin
Randomize;
// Initialize an array
For I: = 0 to 5 do
Begin
FArray [I]. data: = Random (100 );
FArray [I]. index: = I;
Memo1.Lines. Add (Format ('data: % d; No.: % d', [fArray [I]. data, fArray [I]. index]);
End;
// Sort
For I: = High (fArray) downto Low (fArray) do
For J: = Low (fArray) to High (fArray)-1 do
If fArray [J]. data> fArray [J + 1]. data then
Begin
T: = fArray [J];
FArray [J]: = fArray [J + 1];
FArray [J + 1]: = T;
End;
// Display the result
For I: = 0 to 5 do
Memo2.Lines. Add (Format ('data: % d; SN: % d', [fArray [I]. data, fArray [I]. index])
End;
End.
Back up, I sorted it from small to large. you can adjust it.
This is the result !! I'm depressed !!!! Thank you !!!!!!!;
3Q3Q3Q3Q;