zvoulgaris

Stalin Sort Drill

Jan 20th, 2021
653
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Stalin sort drill (probably the most useless sorting algorithm out there, but a fun exercise if you have 2-5 minutes to kill)
  2.  
  3. function ssort(x::Array{<:Any, 1})
  4.     n = length(x)
  5.     y = similar(x)
  6.     y[1] = x[1]
  7.     c = 1
  8.  
  9.     for i = 2:n
  10.         if x[i] >= y[c]
  11.             c += 1
  12.             y[c] = x[i]
  13.         end
  14.     end
  15.  
  16.     return y[1:c]
  17. end
  18.  
RAW Paste Data