Skip to content

Instantly share code, notes, and snippets.

@mac-r
Created August 14, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mac-r/3353388 to your computer and use it in GitHub Desktop.
Save mac-r/3353388 to your computer and use it in GitHub Desktop.
Binary Heaps in the Context of Prioritization #1
def sorted_array_shifter(length, n)
random_array = (1..length).to_a.inject(Array.new) do |arr, el|
el = rand(1..el); arr << el;
end
array = random_array.sort {|x,y| y<=>x }
n.times do
array.shift
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment