Talk:Sorting algorithms/Stooge sort: Difference between revisions
(stooge sort LISP implamentation) |
No edit summary |
||
Line 1: | Line 1: | ||
I was wondering if any of |
I was wondering if any of you can help me. I have implemented a few sorting algorithms in other languages but doing something as simple as the stooge sort seems to be confusing me. I am going this implementation in NewLisp for practice. I like the language so far but i seem to hit a snag in this latest code: |
||
<lang NewLISP> |
<lang NewLISP> |
||
(define (stoogesort L left right)(if (> ( L left ) ( L right )) (swap ( L left) ( L right ))) |
(define (stoogesort L left right)(if (> ( L left ) ( L right )) (swap ( L left) ( L right ))) |
Revision as of 18:44, 24 July 2010
I was wondering if any of you can help me. I have implemented a few sorting algorithms in other languages but doing something as simple as the stooge sort seems to be confusing me. I am going this implementation in NewLisp for practice. I like the language so far but i seem to hit a snag in this latest code: <lang NewLISP> (define (stoogesort L left right)(if (> ( L left ) ( L right )) (swap ( L left) ( L right ))) (if (>= (+ left 1) right) L)
- (round (/ right 3))
(stoogesort(L left (- right (round (/ right 3))))) (stoogesort(L (+ left (round (/ right 3))) right)) (stoogesort(L left (- right (round (/ right 3)))))L)
(stoogesort (list 7 3 2 3 4 0 0 0 0 0) 0 9)
</lang>
I get the following as output: > <lang NewLISP> (lambda (L left right) (if (> (L left) (L right)) (swap (L left) (L right))) (if (>= (+ left 1) right) L) (stoogesort (L left (- right (round (/ right 3))))) (stoogesort (L (+ left (round (/ right 3))) right)) (stoogesort (L left (- right (round (/ right 3))))) L)
ERR: illegal parameter type in function > : left called from user defined function stoogesort called from user defined function stoogesort </lang> --Michael Chrisco