>> I tried writing a naive implementation of quicksort using an >> accumulator. Right now, the code is stack-consuming and returns a >> stackoverflowerror on large lists. Is there any way to prevent it from >> consuming stack with some changes? The code is as follows - > > You don't say what your test data is, but pretty much any quicksort > implementation will have some nasty test cases for which its memory > usage is nasty and its performance is worse. Given that this is a > simple implementation, data that is already sorted is the degenerate > case. > > I don't think you can keep it from using any stack - a non-recursive > implementation would just have to maintain it's own stack state. You > can do some things to make it use less stack, though.
This is just a toy implementation, not something real :) I am interested in learning about making this code truly tail recursive and/or lazy. Identical implementations on Haskell work just fine, so I wrote this one for some testing... When you try using some large numbers like 10 million, it blows the stack. A completely lazy solution is possible in Clojure, as shown in "The Joy of Clojure". Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
