0 Replies - 1782 Views - Last Post: 15 August 2011 - 10:09 AM

#1 krzysz00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

[Lisp] Quicksort

Posted 15 August 2011 - 10:09 AM

Description: Insert the snippet into your program (preferably before it is first called, to avoid warnings) and call the function quicksort when needed.This is an implementation of the quicksort algorithm in Common Lisp. Given a list of numbers, it will sort them in order from least to greatest
(defun quicksort (list)
  (when (<= (length list) 1) (return-from quicksort list))
  (let ((pivot (car list)) (to-be-sorted (cdr list)) (less nil) (greater nil))
    (loop for i in to-be-sorted do
	 (if (< i pivot) (push i less) (push i greater)))
    (append (quicksort less) (list pivot) (quicksort greater))))



Is This A Good Question/Topic? 0
  • +

Page 1 of 1