P. 1
PicoLisp by Example

PicoLisp by Example

|Views: 4,237|Likes:
Published by tj64
More than 600 PicoLisp solutions for Rosetta Code programming tasks from a wide range of topics, written by Alexander Burger (the creator of PicoLisp) himself - plus the complete PicoLisp function reference. Learn a fascinating programming language that maximises expressive power while minimizing complexity 'by Example'.
More than 600 PicoLisp solutions for Rosetta Code programming tasks from a wide range of topics, written by Alexander Burger (the creator of PicoLisp) himself - plus the complete PicoLisp function reference. Learn a fascinating programming language that maximises expressive power while minimizing complexity 'by Example'.

More info:

Published by: tj64 on Aug 23, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/09/2014

pdf

text

original

The Comb Sort is a variant of the Bubble Sort. Like the Shell sort, the Comb
Sort increases the gap used in comparisons and exchanges (dividing the gap
by

· Combsort11 makes sure the gap ends in (11, 8, 6, 4, 3, 2, 1), which is
significantly faster than the other two possible endings

· Combsort with different endings changes to a more efficient sort when the
data is almost sorted (when the gap is small). Comb sort with a low gap
isn’t much better than the Bubble Sort.

Pseudocode:

function combsort(array input)
gap:= input.size //initialize gap size
loop until gap = 1 and swaps = 0
//update the gap value for a next comb. Below is an example
gap:= int(gap / 1.25)
if gap < 1
//minimum gap is 1
gap:= 1
end if
i:= 0
swaps:= 0 //see Bubble Sort for an explanation
//a single "comb" over the input list
loop until i + gap >= input.size //see Shell sort for similar idea
if input[i] > input[i+gap]
swap(input[i], input[i+gap])
swaps:= 1 // Flag a swap has occurred, so the
// list is not guaranteed sorted

end if
i:= i + 1

end loop

end loop
end function

21 Rosetta Code Tasks starting with S

855

(de combSort (Lst)
(let (Gap (length Lst) Swaps NIL)
(while (or (> Gap 1) Swaps)
(setq Gap (max 1 (/ (* Gap 4) 5)))
(off Swaps)
(use Lst

(for (G (cdr (nth Lst Gap)) G (cdr G))
(when (> (car Lst) (car G))
(xchg Lst G)
(on Swaps) )
(pop ’Lst) ) ) ) )

Lst )

Output:

: (combSort (88 18 31 44 4 0 8 81 14 78 20 76 84 33 73 75 82 5 62 70))
-> (0 4 5 8 14 18 20 31 33 44 62 70 73 75 76 78 81 82 84 88)

856

21 Rosetta Code Tasks starting with S

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->