task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Common_Lisp
Common Lisp
(defun quicksort (list &aux (pivot (car list)) ) (if (cdr list) (nconc (quicksort (remove-if-not #'(lambda (x) (< x pivot)) list)) (remove-if-not #'(lambda (x) (= x pivot)) list) (quicksort (remove-if-not #'(lambda (x) (> x pivot)) list))) list))
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PicoLisp
PicoLisp
(de leftmost (Lst N H) (let L 1 (while (<= L H) (use (X) (setq X (/ (+ L H) 2)) (if (>= (caar (nth Lst X)) N) (setq H (dec X)) (setq L (inc X)) ) ) ) L ) )   (de patience (Lst) (let (L (cons (cons (car Lst))) C 1 M NIL) (for N (cdr Ls...
http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort
Sorting algorithms/Insertion sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Clojure
Clojure
  (defn insertion-sort [coll] (reduce (fn [result input] (let [[less more] (split-with #(< % input) result)] (concat less [input] more))) [] coll))  
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C
C
#include <stdio.h>   int max (int *a, int n, int i, int j, int k) { int m = i; if (j < n && a[j] > a[m]) { m = j; } if (k < n && a[k] > a[m]) { m = k; } return m; }   void downheap (int *a, int n, int i) { while (1) { int j = max(a, n, i, 2 * i + 1, 2 * i + 2); ...
http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
Sorting algorithms/Merge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#AutoHotkey_L
AutoHotkey_L
#NoEnv   Test := [] Loop 100 { Random n, 0, 999 Test.Insert(n) } Result := MergeSort(Test) Loop % Result.MaxIndex() { MsgBox, 1, , % Result[A_Index] IfMsgBox Cancel Break } Return     /* Function MergeSort Sorts an array by first recursively splitting it down to its individua...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Nim
Nim
import algorithm   proc pancakeSort[T](list: var openarray[T]) = var length = list.len if length < 2: return   var moves = 0   for i in countdown(length, 2): var maxNumPos = 0 for a in 0 ..< i: if list[a] > list[maxNumPos]: maxNumPos = a   if maxNumPos == i - 1: continue   if maxNu...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#OCaml
OCaml
let rec sorted = function | [] -> (true) | x::y::_ when x > y -> (false) | x::xs -> sorted xs   let rev_until_max li = let rec aux acc greater prefix suffix = function | x::xs when x > greater -> aux (x::acc) x acc xs xs | x::xs -> aux (x::acc) greater prefix suffix xs | [] -> (greater, (prefix @ suffix))...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#REXX
REXX
/*REXX program sorts an integer array @. [the first element starts at index zero].*/ parse arg N . /*obtain an optional argument from C.L.*/ if N=='' | N=="," then N=19 /*Not specified? Then use the default.*/ call gen@ ...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#jq
jq
# Sort any array def selection_sort: def swap(i;j): if i == j then . else .[i] as $tmp | .[i] = .[j] | .[j] = $tmp end; length as $length | reduce range(0; $length) as $currentPlace # state: $array ( .; . as $array | (reduce range( $currentPlace; $length) as $check # state:...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Soundex[ input_ ] := Module[{x = input, head, body}, {head, body} = {First@#, Rest@#}&@ToLowerCase@Characters@x; body = (Select[body, FreeQ[Characters["aeiouyhw"],#]&] /. {("b"|"f"|"p"|"v")->1, ("c"|"g"|"j"|"k"|"q"|"s"|"x"|"z")->2, ("d"|"t")->3,"l"->4 ,("m"|"n")->5, "r"->6}); If[Length[body] < 3, body = PadRight[body,...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PL.2FI
PL/I
  /* Based on Rosetta Fortran */ Shell_Sort: PROCEDURE (A); DECLARE A(*) FIXED; DECLARE ( i, j, increment) FIXED BINARY (31); DECLARE temp FIXED;   increment = DIMENSION(a) / 2; DO WHILE (increment > 0); DO i = lbound(A,1)+increment TO hbound(a,1); j = i; temp = a(i); ...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PowerShell
PowerShell
Function ShellSort( [Array] $data ) { # http://oeis.org/A108870 $A108870 = [Int64[]] ( 1, 4, 9, 20, 46, 103, 233, 525, 1182, 2660, 5985, 13467, 30301, 68178, 153401, 345152, 776591, 1747331, 3931496, 8845866, 19903198, 44782196, 100759940, 226709866, 510097200, 1147718700, 2582367076, 5810325920, 13073233321, 2941477...
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Oberon-2
Oberon-2
  MODULE Stacks; IMPORT Object, Object:Boxed, Out := NPCT:Console;   TYPE Pool(E: Object.Object) = POINTER TO ARRAY OF E; Stack*(E: Object.Object) = POINTER TO StackDesc(E); StackDesc*(E: Object.Object) = RECORD pool: Pool(E); cap-,top: LONGINT; END;   PROCEDURE (s: Stack(E)) INIT*(cap: LONGINT...
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#Prolog
Prolog
  % Prolog implementation: SWI-Prolog 7.2.3   replace([_|T], 0, E, [E|T]) :- !. replace([H|T], N, E, Xs) :- succ(N1, N), replace(T, N1, E, Xs1), Xs = [H|Xs1].   % True if Xs is the Original grid with the element at (X, Y) replaces by E. replace_in([H|T], (0, Y), E, Xs) :- replace(H, Y, E, NH), Xs = [NH|T], !. r...
http://rosettacode.org/wiki/Sorting_algorithms/Radix_sort
Sorting algorithms/Radix sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Wren
Wren
// counting sort of 'a' according to the digit represented by 'exp' var countSort = Fn.new { |a, exp| var n = a.count var output = [0] * n var count = [0] * 10 for (i in 0...n) { var t = (a[i]/exp).truncate % 10 count[t] = count[t] + 1 } for (i in 1..9) count[i] = count[i] + cou...
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Cowgol
Cowgol
include "cowgol.coh";   # Comparator interface, on the model of C, i.e: # foo < bar => -1, foo == bar => 0, foo > bar => 1 typedef CompRslt is int(-1, 1); interface Comparator(foo: intptr, bar: intptr): (rslt: CompRslt);   # Quicksort an array of pointer-sized integers given a comparator function # (This is the closest...
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Prolog
Prolog
patience_sort(UnSorted,Sorted) :- make_piles(UnSorted,[],Piled), merge_piles(Piled,[],Sorted).   make_piles([],P,P). make_piles([N|T],[],R) :- make_piles(T,[[N]],R). make_piles([N|T],[[P|Pnt]|Tp],R) :- N =< P, make_piles(T,[[N,P|Pnt]|Tp],R). make_piles([N|T],[[P|Pnt]|Tp],R) :- N > P, make_piles(T,[[N],[P|Pnt]|Tp...
http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort
Sorting algorithms/Insertion sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#CLU
CLU
% Insertion-sort an array in place. insertion_sort = proc [T: type] (a: array[T]) where T has lt: proctype (T,T) returns (bool)   bound_lo: int := array[T]$low(a) bound_hi: int := array[T]$high(a)   for i: int in int$from_to(bound_lo, bound_hi) do value: T := a[i] j: int := i...
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C.23
C#
using System; using System.Collections.Generic; using System.Text;   public class HeapSortClass { public static void HeapSort<T>(T[] array) { HeapSort<T>(array, 0, array.Length, Comparer<T>.Default); }   public static void HeapSort<T>(T[] array, int offset, int length, IComparer<T> comparer) ...
http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
Sorting algorithms/Merge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#AutoHotkey
AutoHotkey
MsgBox % MSort("") MsgBox % MSort("xxx") MsgBox % MSort("3,2,1") MsgBox % MSort("dog,000000,cat,pile,abcde,1,zz,xx,z")   MSort(x) { ; Merge-sort of a comma separated list If (2 > L:=Len(x)) Return x ; empty or single ...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PARI.2FGP
PARI/GP
pancakeSort(v)={ my(top=#v); while(top>1, my(mx=1,t); for(i=2,top,if(v[i]>v[mx], mx=i)); if(mx==top, top--; next); for(i=1,mx\2, t=v[i]; v[i]=v[mx+1-i]; v[mx+1-i]=t ); for(i=1,top\2, t=v[i]; v[i]=v[top+1-i]; v[top+1-i]=t ); top-- ); v };
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Ring
Ring
  test = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1] stoogeSort(test, 1, len(test)) for i = 1 to 10 see "" + test[i] + " " next see nl   func stoogeSort list, i, j if list[j] < list[i] temp = list[i] list[i] = list[j] list[j] = temp ok if j - i > 1 t = (j - i + 1)/3 stoo...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Ruby
Ruby
class Array def stoogesort self.dup.stoogesort! end   def stoogesort!(i = 0, j = self.length-1) if self[j] < self[i] self[i], self[j] = self[j], self[i] end if j - i > 1 t = (j - i + 1)/3 stoogesort!(i, j-t) stoogesort!(i+t, j) stoogesort!(i, j-t) end self e...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Julia
Julia
function selectionsort!(arr::Vector{<:Real}) len = length(arr) if len < 2 return arr end for i in 1:len-1 lmin, j = findmin(arr[i+1:end]) if lmin < arr[i] arr[i+j] = arr[i] arr[i] = lmin end end return arr end   v = rand(-10:10, 10) println("# unordere...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Kotlin
Kotlin
fun <T : Comparable<T>> Array<T>.selection_sort() { for (i in 0..size - 2) { var k = i for (j in i + 1..size - 1) if (this[j] < this[k]) k = j   if (k != i) { val tmp = this[i] this[i] = this[k] this[k] = tmp } } }  ...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#MUMPS
MUMPS
SOUNDEX(X,NARA=0)  ;Converts a string to its Soundex value.  ;Empty strings return "0000". Non-alphabetic ASCII characters are ignored.  ;X is the name to be converted to Soundex  ;NARA is a flag, defaulting to zero, for which implementation to perform.  ;If NARA is 0, do what seems to be the Knuth implementation  ;If ...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PureBasic
PureBasic
#STEP=2.2   Procedure Shell_sort(Array A(1)) Protected l=ArraySize(A()), increment=Int(l/#STEP) Protected i, j, temp While increment For i= increment To l j=i temp=A(i) While j>=increment And A(j-increment)>temp A(j)=A(j-increment) j-increment Wend A(j)=temp N...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Python
Python
def shell(seq): inc = len(seq) // 2 while inc: for i, el in enumerate(seq[inc:], inc): while i >= inc and seq[i - inc] > el: seq[i] = seq[i - inc] i -= inc seq[i] = el inc = 1 if inc == 2 else inc * 5 // 11
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Objeck
Objeck
stack := IntStack->New(); stack->Push(13); stack->Push(7); (stack->Pop() + stack->Pop())->PrintLine(); stack->IsEmpty()->PrintLine();
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#PureBasic
PureBasic
Procedure spiralMatrix(size = 1) Protected i, x = -1, y, count = size, n Dim a(size - 1,size - 1)   For i = 1 To count x + 1 a(x,y) = n n + 1 Next   Repeat count - 1 For i = 1 To count y + 1 a(x,y) = n n + 1 Next For i = 1 To count x - 1 a(x,y) = n ...
http://rosettacode.org/wiki/Sorting_algorithms/Radix_sort
Sorting algorithms/Radix sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#zkl
zkl
fcn radixSort(ns){ // ints only, inplace, ns is mutable b:=(0).pump(20,List,List().copy); // 20 [empty] buckets: -10..10 z:=ns.reduce(fcn(a,b){ a.abs().max(b.abs()) },0); // |max or min of input| m:=1; while(z){ ns.apply2('wrap(n){ b[(n/m)%10 +10].append(n) }); // sort on right digit ns.clear()...
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Crystal
Crystal
def quick_sort(a : Array(Int32)) : Array(Int32) return a if a.size <= 1 p = a[0] lt, rt = a[1 .. -1].partition { |x| x < p } return quick_sort(lt) + [p] + quick_sort(rt) end   a = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0] puts quick_sort(a) # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Python
Python
from functools import total_ordering from bisect import bisect_left from heapq import merge   @total_ordering class Pile(list): def __lt__(self, other): return self[-1] < other[-1] def __eq__(self, other): return self[-1] == other[-1]   def patience_sort(n): piles = [] # sort into piles for x in n: ...
http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort
Sorting algorithms/Insertion sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#CMake
CMake
# insertion_sort(var [value1 value2...]) sorts a list of integers. function(insertion_sort var) math(EXPR last "${ARGC} - 1") # Sort ARGV[1..last]. foreach(i RANGE 1 ${last}) # Extend the sorted area to ARGV[1..i]. set(b ${i}) set(v ${ARGV${b}}) # Insert v == ARGV[b] in sorted order. While b...
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C.2B.2B
C++
g++ -std=c++11 heap.cpp
http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
Sorting algorithms/Merge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#BBC_BASIC
BBC BASIC
DEFPROC_MergeSort(Start%,End%) REM ***************************************************************** REM This procedure Merge Sorts the chunk of data% bounded by REM Start% & End%. REM *****************************************************************   LOCAL Middle% IF End%=Start% ENDPROC   IF End%-Start%=1 THEN IF ...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Pascal
Pascal
Program PancakeSort (output);   procedure flip(var b: array of integer; last: integer);   var swap, i: integer;   begin for i := low(b) to (last - low(b) - 1) div 2 do begin swap := b[i]; b[i] := b[last-(i-low(b))]; b[last-(i-low(b))] := swap; end; end; ...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Rust
Rust
fn stoogesort<E>(a: &mut [E]) where E: PartialOrd { let len = a.len();   if a.first().unwrap() > a.last().unwrap() { a.swap(0, len - 1); } if len - 1 > 1 { let t = len / 3; stoogesort(&mut a[..len - 1]); stoogesort(&mut a[t..]); stoogesort(&mut a[..len - 1]); ...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Scala
Scala
object StoogeSort extends App { def stoogeSort(a: Array[Int], i: Int, j: Int) { if (a(j) < a(i)) { val temp = a(j) a(j) = a(i) a(i) = temp } if (j - i > 1) { val t = (j - i + 1) / 3 stoogeSort(a, i, j - t) stoogeSort(a, i + t, j) stoogeSort(a, i, j - t) } } ...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Liberty_BASIC
Liberty BASIC
itemCount = 20 dim A(itemCount) for i = 1 to itemCount A(i) = int(rnd(1) * 100) next i   print "Before Sort" gosub [printArray]   '--- Selection sort algorithm for i = 1 to itemCount-1 jMin = i for j = i+1 to itemCount if A(j) < A(jMin) then jMin = j ...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#NetRexx
NetRexx
  class Soundex   method get_soundex(in_) static in = in_.upper() old_alphabet= 'AEIOUYHWBFPVCGJKQSXZDTLMNR' new_alphabet= '@@@@@@**111122222222334556' word='' loop i=1 for in.length() tmp_=in.substr(i, 1) /*obtain a character from word*/ if tmp_.datatype('M') then word=word||tmp_ ...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Racket
Racket
  #lang racket (define (shell-sort! xs) (define ref (curry vector-ref xs)) (define (new Δ) (if (= Δ 2) 1 (quotient (* Δ 5) 11))) (let loop ([Δ (quotient (vector-length xs) 2)]) (unless (= Δ 0) (for ([xᵢ (in-vector xs)] [i (in-naturals)]) (let while ([i i]) (cond [(and (>= i Δ) (> (ref ...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Raku
Raku
sub shell_sort ( @a is copy ) { loop ( my $gap = (@a/2).round; $gap > 0; $gap = ( $gap * 5 / 11 ).round ) { for $gap .. @a.end -> $i { my $temp = @a[$i];   my $j; loop ( $j = $i; $j >= $gap; $j -= $gap ) { my $v = @a[$j - $gap]; last if $v ...
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Objective-C
Objective-C
NSMutableArray *stack = [NSMutableArray array]; // creating   [stack addObject:value]; // pushing   id value = [stack lastObject]; [stack removeLastObject]; // popping   [stack count] == 0 // is empty?
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#Python
Python
def spiral(n): dx,dy = 1,0 # Starting increments x,y = 0,0 # Starting location myarray = [[None]* n for j in range(n)] for i in xrange(n**2): myarray[x][y] = i nx,ny = x+dx, y+dy if 0<=nx<n and 0<=ny<n and myarray[nx][ny] == None: x,y = nx,ny ...
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Curry
Curry
-- quicksort using higher-order functions:   qsort :: [Int] -> [Int] qsort [] = [] qsort (x:l) = qsort (filter (<x) l) ++ x : qsort (filter (>=x) l)   goal = qsort [2,3,1,0]
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Quackery
Quackery
[ dip [ 0 over size rot ] nested bsearchwith [ -1 peek dip [ -1 peek ] > ] drop ] is searchpiles ( [ n --> n )   [ dup size dup 1 = iff [ drop 0 peek ] done 2 / split recurse swap recurse merge ] is k-merge ( [ --> [ )   [ 1 sp...
http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort
Sorting algorithms/Insertion sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#COBOL
COBOL
C-PROCESS SECTION. PERFORM E-INSERTION VARYING WB-IX-1 FROM 1 BY 1 UNTIL WB-IX-1 > WC-SIZE.   ...   E-INSERTION SECTION. E-000. MOVE WB-ENTRY(WB-IX-1) TO WC-TEMP. SET WB-IX-2 TO WB-IX-1.   PERFORM F-PASS UNTIL WB-IX-2 NOT > ...
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Clojure
Clojure
(defn- swap [a i j] (assoc a i (nth a j) j (nth a i)))   (defn- sift [a pred k l] (loop [a a x k y (inc (* 2 k))] (if (< (inc (* 2 x)) l) (let [ch (if (and (< y (dec l)) (pred (nth a y) (nth a (inc y)))) (inc y) y)] (if (pred (nth a x) (nth a ch)) (recur...
http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
Sorting algorithms/Merge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#BCPL
BCPL
get "libhdr"   let mergesort(A, n) be if n >= 2 $( let m = n / 2 mergesort(A, m) mergesort(A+m, n-m) merge(A, n, m) $) and merge(A, n, m) be $( let i, j = 0, m let x = getvec(n) for k=0 to n-1 x!k := A!valof test j~=n & (i=m | A!j < A!i) $( j := j + 1 ...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Perl
Perl
sub pancake { my @x = @_; for my $idx (0 .. $#x - 1) { my $min = $idx; $x[$min] > $x[$_] and $min = $_ for $idx + 1 .. $#x;   next if $x[$min] == $x[$idx];   @x[$min .. $#x] = reverse @x[$min .. $#x] if $x[$min] != $x[-1]; ...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Sidef
Sidef
func stooge(x, i, j) { if (x[j] < x[i]) { x.swap(i, j) }   if (j-i > 1) { var t = ((j - i + 1) / 3) stooge(x, i, j - t) stooge(x, i + t, j ) stooge(x, i, j - t) } }   var a = 10.of { 100.irand }   say "Before #{a}" stooge(a, 0, a.end) say "After #{a}"
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Smalltalk
Smalltalk
OrderedCollection extend [ stoogeSortFrom: i to: j [ (self at: j) < (self at: i) ifTrue: [ self swapElement: i with: j ]. j - i > 1 ifTrue: [ |t| t := (j - i + 1)//3. self stoogeSortFrom: i to: (j-t). self stoogeSortFrom: (i+t) to: j. self stoogeSortFrom: i to: (j-t) ...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#LSE
LSE
  (* ** Tri par Sélection ** (LSE2000) *) PROCEDURE &Test(TABLEAU DE ENTIER pDonnees[], ENTIER pTaille) LOCAL pTaille ENTIER i, j, minimum, tmp POUR i <- 0 JUSQUA pTaille-1 FAIRE minimum <- i POUR j <- i+1 JUSQUA pTaille FAIRE SI pDonnees[j] < pDonnees[minimum] ALORS ...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Lua
Lua
function SelectionSort( f ) for k = 1, #f-1 do local idx = k for i = k+1, #f do if f[i] < f[idx] then idx = i end end f[k], f[idx] = f[idx], f[k] end end     f = { 15, -3, 0, -1, 5, 4, 5, 20, -8 }   SelectionSort( f )   for i i...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#Nim
Nim
import strutils   const Wovel = 'W' # Character code used to specify a wovel. Ignore = ' ' # Character code used to specify a character to ignore ('h', 'w' or non-letter).     proc code(ch: char): char = ## Return the soundex code for a character. case ch.toLowerAscii() of 'b', 'f', 'p', 'v': '1' of 'c',...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#REXX
REXX
/*REXX program sorts a stemmed array using the shell sort (shellsort) algorithm. */ call gen /*generate the array elements. */ call show 'before sort' /*display the before array elements. */ say copies('▒', 75) ...
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#OCaml
OCaml
exception Stack_empty   class ['a] stack = object (self) val mutable lst : 'a list = []   method push x = lst <- x::lst   method pop = match lst with [] -> raise Stack_empty | x::xs -> lst <- xs; x   method is_empty = lst = [] end
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#Quackery
Quackery
[ stack ] is stepcount ( --> s ) [ stack ] is position ( --> s ) [ stack ] is heading ( --> s )   [ heading take behead join heading put ] is right ( --> )   [ heading share 0 peek unrot times [ position...
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#D
D
import std.stdio : writefln, writeln; import std.algorithm: filter; import std.array;   T[] quickSort(T)(T[] xs) => xs.length == 0 ? [] : xs[1 .. $].filter!(x => x< xs[0]).array.quickSort ~ xs[0 .. 1] ~ xs[1 .. $].filter!(x => x>=xs[0]).array.quickSort;   void main() => [4, 65, 2, -31, 0, 99, 2,...
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Racket
Racket
#lang racket/base (require racket/match racket/list)   ;; the car of a pile is the "bottom", i.e. where we place a card (define (place-greedily ps-in c <?) (let inr ((vr null) (ps ps-in)) (match ps [(list) (reverse (cons (list c) vr))] [(list (and psh (list ph _ ...)) pst ...) #:when (<? c ph) ...
http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort
Sorting algorithms/Insertion sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Common_Lisp
Common Lisp
(defun span (predicate list) (let ((tail (member-if-not predicate list))) (values (ldiff list tail) tail)))   (defun less-than (x) (lambda (y) (< y x)))   (defun insert (list elt) (multiple-value-bind (left right) (span (less-than elt) list) (append left (list elt) right)))   (defun insertion-sort (list) ...
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#CLU
CLU
% Sort an array in place using heap-sort. The contained type % may be any type that can be compared. heapsort = cluster [T: type] is sort where T has lt: proctype (T,T) returns (bool) rep = null aT = array[T]   sort = proc (a: aT)  % CLU arrays may start at any index.  % For simpli...
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#COBOL
COBOL
>>SOURCE FORMAT FREE *> This code is dedicated to the public domain *> This is GNUCOBOL 2.0 identification division. program-id. heapsort. environment division. configuration section. repository. function all intrinsic. data division. working-storage section. 01 filler. 03 a pic 99. 03 a-start pic 99...
http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
Sorting algorithms/Merge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C
C
#include <stdio.h> #include <stdlib.h>   void merge (int *a, int n, int m) { int i, j, k; int *x = malloc(n * sizeof (int)); for (i = 0, j = m, k = 0; k < n; k++) { x[k] = j == n ? a[i++] : i == m ? a[j++] : a[j] < a[i] ? a[j++] : a[i++]...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Phix
Phix
with javascript_semantics function pancake_sort(sequence s) s = deep_copy(s) for i=length(s) to 2 by -1 do integer m = largest(s[1..i],true) if m<i then if m>1 then s[1..m] = reverse(s[1..m]) end if s[1..i] = reverse(s[1..i]) end if ...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Swift
Swift
func stoogeSort(inout arr:[Int], _ i:Int = 0, var _ j:Int = -1) { if j == -1 { j = arr.count - 1 }   if arr[i] > arr[j] { swap(&arr[i], &arr[j]) }   if j - i > 1 { let t = (j - i + 1) / 3 stoogeSort(&arr, i, j - t) stoogeSort(&arr, i + t, j) stoogeSort...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Maple
Maple
arr:= Array([17,3,72,0,36,2,3,8,40,0]): len := numelems(arr): for i to len-1 do j_min := i: for j from i+1 to len do if arr[j] < arr[j_min] then j_min := j: end if: end do: if (not j_min = i) then temp := arr[i]: arr[i] := arr[j_min]: arr[j_min] := temp: end if: end do: arr;
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#Objeck
Objeck
class SoundEx { function : Main(args : String[]) ~ Nil { SoundEx("Soundex")->PrintLine(); SoundEx("Example")->PrintLine(); SoundEx("Sownteks")->PrintLine(); SoundEx("Ekzampul")->PrintLine(); }   function : SoundEx(s : String) ~ String { input := s->ToUpper()->Get(0); code := input->T...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Ring
Ring
  aList = [-12, 3, 0, 4, 7, 4, 8, -5, 9] shellSort(aList) for i=1 to len(aList) see "" + aList[i] + " " next   func shellSort a inc = ceil( len(a) / 2 ) while inc > 0 for i = inc to len(a) tmp = a[i] j = i while j > inc and a[j-inc] > tmp ...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Ruby
Ruby
class Array def shellsort! inc = length / 2 while inc != 0 inc.step(length-1) do |i| el = self[i] while i >= inc and self[i - inc] > el self[i] = self[i - inc] i -= inc end self[i] = el end inc = (inc == 2 ? 1 : (inc * 5.0 / 11).to_i) e...
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Oforth
Oforth
ListBuffer Class new: Stack Stack method: push self add ; Stack method: pop self removeLast ; Stack method: top self last ;
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#R
R
spiral <- function(n) matrix(order(cumsum(rep(rep_len(c(1, n, -1, -n), 2 * n - 1), n - seq(2 * n - 1) %/% 2))), n, byrow = T) - 1   spiral(5)
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Dart
Dart
quickSort(List a) { if (a.length <= 1) { return a; }   var pivot = a[0]; var less = []; var more = []; var pivotList = [];   // Partition a.forEach((var i){ if (i.compareTo(pivot) < 0) { less.add(i); } else if (i.compareTo(pivot) > 0) { more.add(i); } else { pivotLi...
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Raku
Raku
multi patience(*@deck) { my @stacks; for @deck -> $card { with @stacks.first: $card before *[*-1] -> $stack { $stack.push: $card; } else { @stacks.push: [$card]; } } gather while @stacks { take .pop given min :by(*[*-1]), @stacks; @...
http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort
Sorting algorithms/Insertion sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#D
D
void insertionSort(T)(T[] data) pure nothrow @safe @nogc { foreach (immutable i, value; data[1 .. $]) { auto j = i + 1; for ( ; j > 0 && value < data[j - 1]; j--) data[j] = data[j - 1]; data[j] = value; } }   void main() { import std.stdio; auto items = [28, 44, 46, 2...
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#CoffeeScript
CoffeeScript
# Do an in-place heap sort. heap_sort = (arr) -> put_array_in_heap_order(arr) end = arr.length - 1 while end > 0 [arr[0], arr[end]] = [arr[end], arr[0]] sift_element_down_heap arr, 0, end end -= 1   put_array_in_heap_order = (arr) -> i = arr.length / 2 - 1 i = Math.floor i while i >= 0 sift_...
http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
Sorting algorithms/Merge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C.23
C#
namespace RosettaCode { using System;   public class MergeSort<T> where T : IComparable { #region Constants public const UInt32 INSERTION_LIMIT_DEFAULT = 12; public const Int32 MERGES_DEFAULT = 6; #endregion   #region Properties public UInt32 InsertionLimit { get; } protected UInt32[] Po...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Picat
Picat
go => Nums = [6,7,8,9,2,5,3,4,1], println(Nums), Sorted = pancake_sort(Nums), println(Sorted), nl.   pancake_sort(L) = L => T = L.len, while (T > 1) Ix = argmax(L[1..T]), if Ix == 1 then L := L[1..T].reverse ++ L.slice(T+1), T := T-1 else L := L[1..Ix].reverse ++ L.slic...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PicoLisp
PicoLisp
(de pancake (Lst) (prog1 (flip Lst (index (apply max Lst) Lst)) (for (L @ (cdr (setq Lst (cdr L))) (cdr L)) (con L (flip Lst (index (apply max Lst) Lst))) ) ) )
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Tcl
Tcl
package require Tcl 8.5   proc stoogesort {L {i 0} {j -42}} { if {$j == -42} {# Magic marker set j [expr {[llength $L]-1}] } set Li [lindex $L $i] set Lj [lindex $L $j] if {$Lj < $Li} { lset L $i $Lj lset L $j $Li } if {$j-$i > 1} { set t [expr {($j-$i+1)/3}] set...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
SelectSort[x_List] := Module[{n = 1, temp, xi = x, j}, While[n <= Length@x, temp = xi[[n]]; For[j = n, j <= Length@x, j++, If[xi[[j]] < temp, temp = xi[[j]]]; ]; xi[[n ;;]] = {temp}~Join~ Delete[xi[[n ;;]], First@Position[xi[[n ;;]], temp] ]; n++; ]; xi ]
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#MATLAB_.2F_Octave
MATLAB / Octave
function list = selectionSort(list)   listSize = numel(list);   for i = (1:listSize-1)   minElem = list(i); minIndex = i;   %This for loop can be vectorized, but there will be no significant %increase in sorting efficiency. for j = (i:listSize) if list(j) ...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#OCaml
OCaml
let c2d = function | 'B' | 'F' | 'P' | 'V' -> "1" | 'C' | 'G' | 'J' | 'K' | 'Q' | 'S' | 'X' | 'Z' -> "2" | 'D' | 'T' -> "3" | 'L' -> "4" | 'M' | 'N' -> "5" | 'R' -> "6" | _ -> ""   let rec dbl acc = function | [] -> (List.rev acc) | [c] -> List.rev(c::acc) | c1::(c2::_ as tl) -> if c1 = c2 ...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Run_BASIC
Run BASIC
siz = 100 dim a(siz) for i = 1 to siz a(i) = rnd(1) * 1000 next i   ' ------------------------------- ' Shell Sort ' ------------------------------- incr = int(siz / 2) WHILE incr > 0 for i = 1 to siz j = i temp = a(i) WHILE (j >= incr and a(abs(j-incr)) > temp) a(j) = a(j-incr) j = j -...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Rust
Rust
  fn shell_sort<T: Ord + Copy>(v: &mut [T]) { let mut gap = v.len() / 2; let len = v.len(); while gap > 0 { for i in gap..len { let temp = v[i]; let mut j = i; while j >= gap && v[j - gap] > temp { v[j] = v[j - gap]; j -= gap; ...
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Ol
Ol
  (define stack #null) (print "stack is: " stack) (print "is stack empty: " (eq? stack #null))   (print "* pushing 1") (define stack (cons 1 stack)) (print "stack is: " stack) (print "is stack empty: " (eq? stack #null))   (print "* pushing 2") (define stack (cons 2 stack)) (print "stack is: " stack) (print "is stack e...
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#Racket
Racket
  #lang racket (require math)   (define (spiral rows columns) (define (index x y) (+ (* x columns) y)) (do ((N (* rows columns)) (spiral (make-vector (* rows columns) #f)) (dx 1) (dy 0) (x 0) (y 0) (i 0 (+ i 1))) ((= i N) spiral) (vector-set! spiral (index y x) i) (let ((nx (+ x d...
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#E
E
def quicksort := {   def swap(container, ixA, ixB) { def temp := container[ixA] container[ixA] := container[ixB] container[ixB] := temp }   def partition(array, var first :int, var last :int) { if (last <= first) { return }   # Choose a pivot def pivot := arra...
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#REXX
REXX
/*REXX program sorts a list of things (or items) using the patience sort algorithm. */ parse arg xxx; say ' input: ' xxx /*obtain a list of things from the C.L.*/ n= words(xxx); #= 0;  !.= 1 /*N: # of things; #: number of piles*/ @.= ...
http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort
Sorting algorithms/Insertion sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Dart
Dart
    insertSort(List<int> array){ for(int i = 1; i < array.length; i++){ int value = array[i]; int j = i - 1; while(j >= 0 && array[j] > value){ array[j + 1] = array[j]; j = j - 1; } array[j + 1] = value; } return array; }   void main() { List<int> a = insertSort([10, 3, 11, 15,...
http://rosettacode.org/wiki/Sorting_algorithms/Heapsort
Sorting algorithms/Heapsort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Common_Lisp
Common Lisp
(defun make-heap (&optional (length 7)) (make-array length :adjustable t :fill-pointer 0))   (defun left-index (index) (1- (* 2 (1+ index))))   (defun right-index (index) (* 2 (1+ index)))   (defun parent-index (index) (floor (1- index) 2))   (defun percolate-up (heap index predicate) (if (zerop index) heap ...
http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
Sorting algorithms/Merge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C.2B.2B
C++
#include <iterator> #include <algorithm> // for std::inplace_merge #include <functional> // for std::less   template<typename RandomAccessIterator, typename Order> void mergesort(RandomAccessIterator first, RandomAccessIterator last, Order order) { if (last - first > 1) { RandomAccessIterator middle = first + ...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PL.2FI
PL/I
  pancake_sort: procedure options (main); /* 23 April 2009 */ declare a(10) fixed, (i, n, loc) fixed binary;   a(1) = 3; a(2) = 9; a(3) = 2; a(4) = 7; a(5) = 10; a(6) = 1; a(7) = 8; a(8) = 5; a(9) = 4; a(10) = 6;   n = hbound(A,1); put skip edit (A) (f(5)); do i = 1 to n-1; loc = max(A, n); ...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PowerShell
PowerShell
Function FlipPancake( [Object[]] $indata, $index = 1 ) { $data=$indata.Clone() $datal = $data.length - 1 if( $index -gt 0 ) { if( $datal -gt $index ) { $first = $data[ $index..0 ] $last = $data[ ( $index + 1 )..$datal ] $data = $first + $last } else { $data = $data[ $index..0 ] } } $data }   F...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#uBasic.2F4tH
uBasic/4tH
PRINT "Stooge sort:" n = FUNC (_InitArray) PROC _ShowArray (n) PROC _Stoogesort (n) PROC _ShowArray (n) PRINT   END     _InnerStooge PARAM(2) ' Stoogesort LOCAL(1)   IF @(b@) < @(a@) Then Proc _Swap (a@, b@) IF b@ - a@ > 1 THEN c@ = (b@ - a@ + 1)/3 PROC _InnerStooge (a@, b@-c@) ...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Wren
Wren
var stoogeSort // recursive stoogeSort = Fn.new { |a, i, j| if (a[j] < a[i]) { var t = a[i] a[i] = a[j] a[j] = t } if (j - i > 1) { var t = ((j - i + 1)/3).floor stoogeSort.call(a, i, j - t) stoogeSort.call(a, i + t, j) stoogeSort.call(a, i, j - t) ...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Maxima
Maxima
selection_sort(v) := block([k, m, n], n: length(v), for i: 1 thru n do ( k: i, m: v[i], for j: i + 1 thru n do if v[j] < m then (k: j, m: v[j]), v[k]: v[i], v[i]: m ))$   v: makelist(random(199) - 99, i, 1, 10); /* [52, -85, 41, -70, -59, 88, 19, 80, 90, 44] */ selection_sort(v)$ v; ...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#Pascal
Pascal
program Soundex;   {$mode objfpc}{$H+}   uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} SysUtils;   type TLang=(en,fr,de);   const Examples : array[1..16, 1..2] of string = (('Ashcraft', 'A261') ,('Ashcroft', 'A261') ,('Gauss', 'G200') ,('Ghosh', 'G200') ,('Hilb...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Scala
Scala
object ShellSort { def incSeq(len:Int)=new Iterator[Int]{ private[this] var x:Int=len/2 def hasNext=x>0 def next()={x=if (x==2) 1 else x*5/11; x} }   def InsertionSort(a:Array[Int], inc:Int)={ for (i <- inc until a.length; temp=a(i)){ var j=i; while (j>=inc && a(j-inc)>temp){ ...