Sorting algorithms/Insertion sort: Difference between revisions

Content deleted Content added
No edit summary
m combined the two Scala header entries into one header, named the two entries Version 1 and Version 2.
Line 2,849: Line 2,849:


=={{header|Scala}}==
=={{header|Scala}}==
===version 1===
<lang scala>def insertSort[X](list: List[X])(implicit ord: Ordering[X]) = {
def insert(list: List[X], value: X) = list.span(x => ord.lt(x, value)) match {
case (lower, upper) => lower ::: value :: upper
}
list.foldLeft(List.empty[X])(insert)
}</lang>

===version 2===
Copied from SASL manual, Appendix II, answer (2)(a)
Copied from SASL manual, Appendix II, answer (2)(a)
<lang SASL>
<lang SASL>
Line 2,858: Line 2,867:
b : insert a x
b : insert a x
?</lang>
?</lang>

=={{header|Scala}}==
<lang scala>def insertSort[X](list: List[X])(implicit ord: Ordering[X]) = {
def insert(list: List[X], value: X) = list.span(x => ord.lt(x, value)) match {
case (lower, upper) => lower ::: value :: upper
}
list.foldLeft(List.empty[X])(insert)
}</lang>


=={{header|Scheme}}==
=={{header|Scheme}}==