Childhood programming algorithm experience notes

zhaozj2021-02-17  29

Author: Firebird

Redbirdli@hotmail.com

The flamingo program has pursued small, fast, fine, so the algorithm has become the direction I have continuously learned and explored, and some experience is posted. For the master criticism, I hope to have some kind of brick introduction. Let's first look at the foundation of flamingo in the registry study (here for the past, time between 1999 - 2000).

The hidden drive algorithm A..Z with 2 N times indicates that hidden A and C are 2 times 2 2 = 5

Var stmp: String;

ITMP, Irun, IVAL: Integer

Begin

IVAL: = 0;

STMP: = Uppercase (edit1.text);

For irun: = 1 to Length (stmp) DO

Begin

ITMP: = ORD (STMP [Irun]) - 66;

ITMP: = Trunc (LDEXP (2, ITMP));

IVAL: = IVAL ITMP;

END;

Edit2.text: = INTOSTR (IVAL);

// More than the forward operation

STMP: = '';

While Ival> 0 DO

Begin

For irun: = 0 to 25 DO if LDEXP (2, Irun> ival the Break;

ival: = IVAL-TRUNC (LDEXP (2, Irun-1);

STMP: = CHR (65 IRUN) STMP;

END;

Edit3.Text: = STMP;

Comments: This method does not seem to have a lot of use, because it will be said with the same characters in the same character, but there must be unique in the string, that is, the same letter cannot be appeared in the second time; 2. Return Characters cannot determine the original arrangement. The chicken rib is also! The flamingo is a use of this method. If you are doing a management system's permission module, you can use letters such as I, O, Q, B, M to indicate it, sales, query, data backup and administrator maintenance, etc. Features. Write the same field after processing it through the algorithm, and can encrypt the illegitimate operation, two can reduce the length of the field. If you convert it into a 16-year or higher (flamingo suggesting that you put the 16 in the concept of f Represents 16 Concept sequence) Your field will be smaller.

The following is a problem with the speed of arithmetic, first declare that flamingo is not a computer, so if you think that these problems are earlier. Don't laugh, you don't think it is. The following is the code:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); // This is a sort of the pointer

Var IT: Array [0..39999] of integer;

ITMP, IRUN, ISET: Integer;

PI: ^ integer;

Begin

For itmp: = 0 to 39999 DO

IT [ITMP]: = 39999-ITMP Random (999);

CAPTION: = Timetostr (TIME) '-'; // Start timing

For itmp: = 0 to 39999 DO

Begin

PI: = @ it [ITMP];

For irun: = ITMP 1 to 39999 DO

IF pi ^> It [irun] THEN PI: = @ it [irun];

ISET: = IT [ITMP];

IT [ITMP]: = Pi ^;

PI ^: = ISET;

END;

CAPTION: = CAPTION TIMETOSTR (TIME); / / The time is over, and it is over about 7 seconds in the firefoot p3 533eb 128m memory;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); // This is the sort of unused pointers

Var IT: Array [0..39999] of integer;

ITMP, IRUN, ISET: Integer;

PI: integer;

Begin

For itmp: = 0 to 39999 DO

IT [ITMP]: = 39999-ITMP Random (999);

CAPTION: = Timetostr (TIME) '-'; // Start timing

For itmp: = 0 to 39999 DO

Begin

PI: = ITMP;

For irun: = ITMP 1 to 39999 DO

IF IT [PI]> IT [Irun] THEN PI: = IRUN;

ISET: = IT [ITMP];

IT [ITMP]: = IT [PI];

IT [PI]: = ISET;

END;

CAPTION: = CAPTION TIMETOSTR (TIME); // Over 10 seconds in the same environment

END;

Comments: The only difference between the above two algorithms is that the first type runs a pointer in the loop, and the second is directly on the value of the value in the loop, and the programming pointer can improve program efficiency.

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); // This is an insertion rule

Var IT: Array [0..39999] of integer;

ITMP, IRUN, ISET: Integer;

PI: integer;

Begin

For itmp: = 0 to 39999 DO

IT [ITMP]: = 39999-ITMP Random (999);

CAPTION: = Timetostr (TIME) '-'; // Start timing

For itmp: = 1 to 39999 DO

Begin

PI: = IT [ITMP];

Irun: = ITMP-1;

While (Pi -1) DO

Begin

IT [irun 1]: = IT [irun];

Irun: = irun-1;

END;

IT [irun 1]: = Pi;

END;

CAPTION: = CAPTION TIMETOSTR (TIME); // Operate 6-7 seconds in the same environment

END;

If you have read the above-in -ced sorting code, let's take a look at the old beauty shell in 1959 (joke: It seems that my mother is still in the insertion method, this method is also called minus Small step method:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Var IT: Array [0..39999] of integer;

ITMP, IRUN, ISET: Integer;

PI: integer;

Begin

For itmp: = 0 to 39999 DO

IT [ITMP]: = 39999-ITMP Random (999);

CAPTION: = Timetostr (TIME) '-'; // Start timing

ISET: = 40000;

While ISET> 1 DO

Begin

ISET: = ISET DIV 2;

ITMP: = ISET;

Repeat

PI: = IT [ITMP];

Irun: = ITMP-ISET; while (irun> -1) and (pi

Begin

IT [Irun ISET]: = IT [irun];

Irun: = irun-iset;

END;

IT [Irun ISET]: = Pi;

ITMP: = ITMP 1;

Until ITMP> 40000

END;

CAPTION: = CAPTION TIMETOSTR (TIME); // The operation is less than 1 second in the same environment! Even if the array is expanded to 199999, it can still be completed in a second!

END;

Comments: The flamingo will only be sorted by the so-called "bubble" before, seeing shell, I really don't deserverate the top, big dreams. It's a delicate algorithm! Set a new sentence "Not just a little bit", you will try it!

Author: Firebird

Redbirdli@hotmail.com

Take a collection class overview .NET Collectes and related technologies via C #

Establish communication and data exchange servers with Delphi - TRANSCEIVER technology (on)

Establish communication and data exchange servers with Delphi - TRANSCEIVER technology (below)

Old Things: Program Shortcut / Program Delete / EXE Self Delete DIY

Old things: childhood programming algorithm

转载请注明原文地址:https://www.9cbs.com/read-30351.html

New Post(0)