CALCAD Posted May 26, 2009 Posted May 26, 2009 Here is an Autolisp implementation of the Quicksort algorithm. It's been a few years, but I think I adapted this code from a C language example. I've used many different sorting routines, but Quicksort is the best for general sorts. (defun qsort (inlist / pivot dpivot ppivot index list1 list2 ) (if (<= (length inlist) 1) inlist (progn (setq ppivot (/ (length inlist) 2)) (setq pivot (cdr (nth ppivot inlist))) (setq dpivot (nth ppivot inlist)) (setq list1 ()) (setq list2 ()) (setq index 0) (while (< index (length inlist)) (if (/= index ppivot) (if (< (cdr (nth index inlist)) pivot) (setq list1 (append list1 (list (nth index inlist)))) (setq list2 (append list2 (list (nth index inlist)))) ) ) (setq index (+ index 1)) ) (setq list1 (qsort list1)) (setq list2 (qsort list2)) (setq inlist (append list1 (list dpivot) list2)) ) ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.