Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix quicksort.lua #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix quicksort.lua #1

wants to merge 1 commit into from

Conversation

kikito
Copy link

@kikito kikito commented Oct 11, 2020

Hello, I realize that this repo is 11 years old, but it is still the first result I get when I google for "Lua quicksort".

Unfortunately its current implementation does not work correctly:

$luajit lua/quicksort.lua
1
1
2
2
3
5
11
17
37
22

I have based this fix on Rosetta stone's Quicksort in-place implementation. As a result I removed the partition helper function and had to change the variable names a little bit in order to make the multiple assignments less wide (which is objective) and more readable (this bit is subjective).

With the fix in place, quicksort.lua now properly sorts the array:

$luajit lua/quicksort.lua
1
1
2
2
3
5
11
17
22
37

@jtarchie
Copy link

Tests!?

@kikito
Copy link
Author

kikito commented Mar 6, 2021

@jtarchie the file lua/quicksort.lua contains a single test. Unfortunately it contains a bug. The first output I printed is with the current implementation. It puts 37 before 22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants