| |

VerySource

 Forgot password?
 Register
Search
View: 799|Reply: 5

Array sorting problem

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-2-12 19:30:01
| Show all posts |Read mode
The fool asked a silly question:
Array strlist1: TStringList; StrList [i]> '0'
How to sort the values ​​in strlist1 in ascending order, with the value of '0' following. ???????
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-4-10 07:45:01
| Show all posts
var
   i, Position, n: integer;
   Value: TStrings;
   Done: boolean;
  begin
    n: = High (Items);
    for i: = 0 to n do
    begin
      Value: = Items [i];
      Position: = i;
      Done: = false;
      while not done do
      begin
       if Position <= 0 then
         Done: = true
       else
         if StrToInt (Value.Strings [13])> = StrToInt (Items [Position-1] .Strings [13]) then
           Done: = true
         else
         begin
             Items [Position]: = Items [Position-1];
             Position: = Position-1;
         end;
      end;
      Items [Position]: = Value;
    end;
    // DownZero (Items);
  end;
**************************** But how to put the data back to 0?
Reply

Use magic Report

0

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 United States

Post time: 2020-6-25 16:00:02
| Show all posts
Special judgment for 0
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-8-7 23:15:01
| Show all posts
Sort by bubble
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-8-7 23:30:01
| Show all posts
There is a dumb way: you can go to 0 for a loop, and put 0 at the back.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-8 00:15:01
| Show all posts
Take special care of 0.
Move the data after 0 forward, and then add 0 at the end.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list