Skip to content

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