Belzebub

bubble_sorting.lua

Mar 5th, 2021
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.44 KB | None | 0 0
  1. local function DoCheck(tab, i1, i2, customcheck)
  2.     if tab[i1] and tab[i2] then
  3.         local b = customcheck(tab[i1], tab[i2])
  4.         tab[i1], tab[i2] = tab[b and i2 or i1], tab[b and i1 or i2]
  5.  
  6.         return true
  7.     end
  8.  
  9.     return false
  10. end
  11.  
  12. function table.BubbleSort(tab, customcheck)
  13.     for i = 1, #tab do
  14.         while DoCheck(tab, i, i + 1, customcheck) do
  15.             i = i - 1
  16.         end
  17.     end
  18.  
  19.     return tab
  20. end
Advertisement
Add Comment
Please, Sign In to add comment