» Indeks > Modding Archive > SAIL - SortList (sortowanie list)
SAIL - SortList (sortowanie list)
Serpent pisze:Napisałem funkcje które umożliwiają sortowanie list rosnąco i malejąco.
Sortowanie rosnące (od minimum do maksimum)
Spoiler:
Kod:
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:
Kod:
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:
Kod:
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: https://forum.original-war.net/viewtopic.php?f=42&t=4685
» Indeks > Modding Archive > SAIL - SortList (sortowanie list)



