Jump to content
Alloder.pro  about Allods with love 😱
Search In
  • More options...
Find results that contain...
Find results in...

Servers monitoring and the Addons Editor

We present you two legends. All dreams come true.

Servers monitoring The Addons Editor

Digest April

We talk about what was done and updated in the past month. We help keep abreast of events.

Read more

Game tooltips

Tooltips provide a way for 3rd party fansites and extensions to display detailed information on mouseover.

Read more

Сортировка массива по индексу


jedbez
 Share

Recommended Posts

Подскажите как можно отсортировать массив по индексу. 

Есть:



local array={
["Гав"]={ON=true},
["Мяу"]={ON=true},
["Шшшш"]={ON=true},
["Апорт"]={ON=true},}

Вывод:



for key,val in array do
  LogInfo("key = ",key,", val = ",val)
end

Соответственно получаю:

 

Info: addon : key = Апорт, val = table: 043308C8
Info: addon : key = Шшшш, val = table: 043308A0
Info: addon : key = Гав, val = table: 4A030B08
Info: addon : key = Мяу, val = table: 4A030B88

 

При сортировке:



local a
local b
table.sort(array, function(a,b ) return a>b end)

Эффекта нет, выводит тоже самое.....

Link to comment
Share on other sites

А разве table.sort работает с какими-то индексами, кроме целочисленных в диапазоне [1, table.maxn]?

 

Напиши сортировку вручную.

Link to comment
Share on other sites

table сорт работает только как описано выше, еще и переставляет одинаковые элементы, как захочет. Посмотри пример сортировки в GuildGui :D

Link to comment
Share on other sites

  • 2 months later...

Если нет встроенной сортировки в самой реализации языка, то возможно стоит реализовать все самому. Тут можно найти подробное описание и реализацию основных алгоритмов сортировки массива.

Link to comment
Share on other sites

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

By using our site you agree to the Terms of Use