Skip to content

Instantly share code, notes, and snippets.

@euccas
Last active June 8, 2020 00:14
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 euccas/7fd3193832c9d7678bfc to your computer and use it in GitHub Desktop.
Save euccas/7fd3193832c9d7678bfc to your computer and use it in GitHub Desktop.
Here are some things you can do with Gists in GistBox.
# Use Gists to store entire functions
class QuickSort
def self.sort!(keys)
quick(keys,0,keys.size-1)
end
private
def self.quick(keys, left, right)
if left < right
pivot = partition(keys, left, right)
quick(keys, left, pivot-1)
quick(keys, pivot+1, right)
end
keys
end
def self.partition(keys, left, right)
x = keys[right]
i = left-1
for j in left..right-1
if keys[j] <= x
i += 1
keys[i], keys[j] = keys[j], keys[i]
end
end
keys[i+1], keys[right] = keys[right], keys[i+1]
i+1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment