Urgent: after sorting array 1-> array 2, evaluate the algorithm! 3Q

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.