SAIL - SortList (sortowanie list)

Gotowe kody SAIL'a, informacje na temat moddingu, itd.

Moderator: zoNE

Post Reply
User avatar

Topic author
zoNE
The Great Uniter & Site Administrator
The Great Uniter & Site Administrator
Posts: 1524
Joined: Fri Feb 17, 2006 3:44 pm
Location: Poland
Contact:

SAIL - SortList (sortowanie list)

#1

Post by zoNE » Sat Mar 12, 2016 10:22 pm

Serpent wrote:Napisałem funkcje które umożliwiają sortowanie list rosnąco i malejąco.


Sortowanie rosnące (od minimum do maksimum)
Spoiler:

Code: Select all

Export Function SortListAsc(list);
var i, j, sort_list, add;
begin
sort_list := [];

for i = 1 to list do
    begin
    if i = 1 then
       sort_list := sort_list ^ list[i]
    else
     begin
     for j = 1 to sort_list do
         begin
         add := false;

         if list[i] < sort_list[j] then
            begin
            sort_list := Insert(sort_list, j, list[i]);
            add := true;
            break;
            end;
         end;
     
     if not add then
        sort_list := sort_list ^ list[i];

     end;
    end;

result := sort_list;
End;
Sortowanie malejące (od maksimum do minimum)
Spoiler:

Code: Select all

Export Function SortListDesc(list);
var i, j, sort_list, add;
begin
sort_list := [];

for i = 1 to list do
    begin
    if i = 1 then
       sort_list := sort_list ^ list[i]
    else
     begin
     for j = 1 to sort_list do
         begin
         add := false;

         if list[i] > sort_list[j] then
            begin
            sort_list := Insert(sort_list, j, list[i]);
            add := true;
            break;
            end;
         end;

     if not add then
        sort_list := sort_list ^ list[i];

     end;
    end;

result := sort_list;
End;
Przykład użycia:

Code: Select all

Export Function Tablica;
var tab1, tab2, tab3;
begin
tab1 := [9, 24, 1, 0, 12];
tab2 := SortListDesc(tab1);
tab3 := SortListAsc(tab1);
display_strings := tab2;
Wait(0$03);
display_strings := tab3;
end;
// tab2 = [24, 12, 9, 1, 0]
// tab3 = [0, 1, 9, 12, 24]
Author: Serpent
Topic: viewtopic.php?f=42&t=4685

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest