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/Bogosort
Sorting algorithms/Bogosort
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 bogo.cpp
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program gnomeSort.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a file...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program countSort.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a file...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Forth
Forth
defer precedes defer exchange   : gnomesort ( a n) swap >r 1 ( n c) begin ( n c) over over > ( n c f) while ( n c) dup if ( n c) dup ...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 in-order? [order xs] (or (empty? xs) (apply order xs)))   (defn bogosort [order xs] (if (in-order? order xs) xs (recur order (shuffle xs))))   (println (bogosort < [7 5 12 1 4 2 23 18]))
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#Arturo
Arturo
gnomeSort: function [items][ i: 1 j: 2 arr: new items while [i < size arr][ if? arr\[i-1] =< arr\[i] [ i: j j: j + 1 ] else [ tmp: arr\[i] arr\[i]: arr\[i-1] arr\[i-1]: tmp   i: i-1 if i=0 [ ...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#Arturo
Arturo
countingSort: function [items, minimum, maximum][ a: new items rng: inc maximum - minimum cnt: array.of: rng 0 z: 0   loop 0..dec size a 'i [ mm: a\[i]-minimum cnt\[mm]: cnt\[mm] + 1 ]   loop minimum..maximum 'i [ loop 0..dec cnt\[i-minimum] 'j [ a\[z]: i...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Fortran
Fortran
program Combsort_Demo implicit none   integer, parameter :: num = 20 real :: array(num)   call random_seed call random_number(array) write(*,*) "Unsorted array:-" write(*,*) array write(*,*) call combsort(array) write(*,*) "Sorted array:-" write(*,*) array   contains   subroutine combsort(a)   ...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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
identification division. program-id. bogo-sort-program. data division. working-storage section. 01 array-to-sort. 05 item-table. 10 item pic 999 occurs 10 times. 01 randomization. 05 random-seed pic 9(8). 05 random-index pic 9. 01 flags-counters-etc. 05 array-i...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 % GnomeSort("") MsgBox % GnomeSort("xxx") MsgBox % GnomeSort("3,2,1") MsgBox % GnomeSort("dog,000000,xx,cat,pile,abcde,1,cat,zz,xx,z")   GnomeSort(var) { ; SORT COMMA SEPARATED LIST StringSplit a, var, `, ; make array, size = a0 i := 2, j := 3 While i <= a0 { ...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#11l
11l
F cocktailSort(&A) L L(indices) ((0 .< A.len-1).step(1), (A.len-2 .. 0).step(-1)) V swapped = 0B L(i) indices I A[i] > A[i + 1] swap(&A[i], &A[i + 1]) swapped = 1B I !swapped R   V test1 = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0] cocktailSo...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 % CountingSort("-1,1,1,0,-1",-1,1)   CountingSort(ints,min,max) { Loop % max-min+1 i := A_Index-1, a%i% := 0 Loop Parse, ints, `, %A_Space%%A_Tab% i := A_LoopField-min, a%i%++ Loop % max-min+1 { i := A_Index-1, v := i+min Loop % a%i% t .= "," v } Return SubStr(t,2)...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#FreeBASIC
FreeBASIC
' version 21-10-2016 ' compile with: fbc -s console ' for boundary checks on array's compile with: fbc -s console -exx   Sub compsort(bs() As Long) ' sort from lower bound to the highter bound ' array's can have subscript range from -2147483648 to +2147483647 Dim As Long lb = LBound(bs) Dim As Long ub =...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 nshuffle (sequence) (loop for i from (length sequence) downto 2 do (rotatef (elt sequence (random i)) (elt sequence (1- i )))) sequence)   (defun sortedp (list predicate) (every predicate list (rest list)))   (defun bogosort (list predicate) (do ((list list (nshuffle list))) ...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#AWK
AWK
#!/usr/bin/awk -f   BEGIN { d[1] = 3.0 d[2] = 4.0 d[3] = 1.0 d[4] = -8.4 d[5] = 7.2 d[6] = 4.0 d[7] = 1.0 d[8] = 1.2 showD("Before: ") gnomeSortD() showD("Sorted: ") exit }   function gnomeSortD( i) { for (i = 2; i <= length(d); i++) { if (d[i] < d[i-1]) gn...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#360_Assembly
360 Assembly
* Cocktail sort 25/06/2016 COCKTSRT CSECT USING COCKTSRT,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) prolog ST R13,4(R15) " ST R15,8(R13) " ...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#BASIC256
BASIC256
  # counting sort   n = 10   dim test(n) test = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}   mn = -31 mx = 782   dim cnt(mx - mn + 1) # count is a reserved string function name   # seems initialized as 0 # for i = 1 to n # print cnt[i] # next i   # sort for i = 0 to n-1 cnt[test[i] - mn] = cnt[test[i] - mn] + 1 next i ...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Gambas
Gambas
Public Sub Main() Dim siToSort As Short[] = [249, 28, 111, 36, 171, 98, 29, 448, 44, 147, 154, 46, 102, 183, 24, 120, 19, 123, 2, 17, 226, 11, 211, 25, 191, 205, 77] Dim siStart As Short Dim siGap As Short = siToSort.Max Dim bSorting, bGap1 As Boolean   Print "To sort: -" ShowWorking(siToSort...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 knuthShuffle(items : Array) i = items.size-1 while i > 1 j = Random.rand(0..i) items.swap(i, j)   i -= 1 end end   def sorted?(items : Array) prev = items[0] items.each do |item| if item < prev return false end prev = item end r...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#BASIC
BASIC
DIM a(0 TO n-1) AS INTEGER '...more code... sort: i = 1 j = 2   WHILE(i < UBOUND(a) - LBOUND(a)) IF a(i-1) <= a(i) THEN i = j j = j + 1 ELSE SWAP a(i-1), a(i) i = i - 1 IF i = 0 THEN i = j j = j + 1 END IF END IF WEND
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#6502_Assembly
6502 Assembly
define z_HL $00 define z_L $00 define z_H $01 define temp $02 define temp2 $03   define yINC $04 define yDEC $05   set_table: dex txa sta $1200,y iny bne set_table ;stores $ff at $1200, $fe at $1201, etc.   lda #$12 sta z_H lda #$00 sta z_L  ;get the base address of the data table     lda #0 tax tay ;clear re...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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
DIM test%(9) test%() = 4, 65, 2, -31, 0, 99, 2, 83, 782, 1 PROCcountingsort(test%(), -31, 782) FOR i% = 0 TO 9 PRINT test%(i%) ; NEXT PRINT END   DEF PROCcountingsort(a%(), l%, h%) LOCAL i%, z%, c%() DIM c%(h% - l%) FOR i% = 0 TO DIM(a%(),1) ...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 counting_sort_mm(int *array, int n, int min, int max) { int i, j, z;   int range = max - min + 1; int *count = malloc(range * sizeof(*array));   for(i = 0; i < range; i++) count[i] = 0; for(i = 0; i < n; i++) count[ array[i] - min ]++;   for(i = min, z = 0; i <=...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Go
Go
package main   import "fmt"   func main() { a := []int{170, 45, 75, -90, -802, 24, 2, 66} fmt.Println("before:", a) combSort(a) fmt.Println("after: ", a) }   func combSort(a []int) { if len(a) < 2 { return } for gap := len(a); ; { if gap > 1 { gap = gap * 4 / 5 ...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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, std.algorithm, std.random;   void bogoSort(T)(T[] data) { while (!isSorted(data)) randomShuffle(data); }   void main() { auto array = [2, 7, 41, 11, 3, 1, 6, 5, 8]; bogoSort(array); writeln(array); }
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#Batch_File
Batch File
@ECHO OFF SETLOCAL EnableExtensions EnableDelayedExpansion :: GnomeSort.cmd in WinNT Batch using pseudo array. :: Set the number of random elements to sort. SET numElements=100 :: Decrement numElements for use in zero-based loops as in (0, 1, %numElements% - 1). SET /A tmpElements=%numElements% - 1 :: Create array of ...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program cocktailSort64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly */ .include "../includeConstante...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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#
using System; using System.Linq;   namespace CountingSort { class Program { static void Main(string[] args) { Random rand = new Random(); // Just for creating a test array int[] arr = new int[100]; // o...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Groovy
Groovy
def makeSwap = { a, i, j -> print "."; a[i] ^= a[j]; a[j] ^= a[i]; a[i] ^= a[j] }   def checkSwap = { a, i, j -> [(a[i] > a[j])].find { it }.each { makeSwap(a, i, j) } }   def combSort = { input -> def swap = checkSwap.curry(input) def size = input.size() def gap = size def swapped = true while (gap...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Delphi
Delphi
def isSorted(list) { if (list.size() == 0) { return true } var a := list[0] for i in 1..!(list.size()) { var b := list[i] if (a > b) { return false } a := b } return true }   def bogosort(list, random) { while (!isSorted(list)) { shuffle(list, random) } }
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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
DEF PROC_GnomeSort1(Size%) I%=2 J%=2 REPEAT IF data%(J%-1) <=data%(J%) THEN I%+=1 J%=I% ELSE SWAP data%(J%-1),data%(J%) J%-=1 IF J%=1 THEN I%+=1 J%=I% ENDIF ENDIF UNTIL I%>Size% ENDPROC
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Action.21
Action!
PROC PrintArray(INT ARRAY a INT size) INT i   Put('[) FOR i=0 TO size-1 DO IF i>0 THEN Put(' ) FI PrintI(a(i)) OD Put(']) PutE() RETURN   PROC CoctailSort(INT ARRAY a INT size) INT i,tmp BYTE swapped   DO swapped=0 i=0 WHILE i<size-1 DO IF a(i)>a(i+1) THEN tmp=a(i...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 <iostream> #include <time.h>   //------------------------------------------------------------------------------ using namespace std;   //------------------------------------------------------------------------------ const int MAX = 30;   //---------------------------------------------------------------------...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Haskell
Haskell
import Data.List import Control.Arrow import Control.Monad   flgInsert x xs = ((x:xs==) &&& id)$ insert x xs   gapSwapping k = (and *** concat. transpose). unzip . map (foldr (\x (b,xs) -> first (b &&)$ flgInsert x xs) (True,[])) . transpose. takeWhile (not.null). unfoldr (Just. splitAt k)   combSort xs = (snd. fst...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 isSorted(list) { if (list.size() == 0) { return true } var a := list[0] for i in 1..!(list.size()) { var b := list[i] if (a > b) { return false } a := b } return true }   def bogosort(list, random) { while (!isSorted(list)) { shuffle(list, random) } }
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 gnomesort(A, len) be $( let i=1 and j=2 and t=? while i < len test A!(i-1) <= A!i $( i := j j := j + 1 $) or $( t := A!(i-1) A!(i-1) := a!i A!i := t i := i - 1 if i = 0 $( i := j...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#ActionScript
ActionScript
function cocktailSort(input:Array):Array { do { var swapped:Boolean=false; for (var i:uint = 0; i < input.length-1; i++) { if (input[i]>input[i+1]) { var tmp=input[i]; input[i]=input[i+1]; input[i+1]=tmp; swapped=true; } } if (! swapped) { break; } for (i = inpu...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 counting-sort (sequence &optional (min (reduce #'min sequence)) (max (reduce #'max sequence))) (let ((i 0) (counts (make-array (1+ (- max min)) :initial-element 0 :element-type `(integer 0 ,(length sequence))))) (...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Haxe
Haxe
class CombSort { @:generic public static function sort<T>(arr:Array<T>) { var gap:Float = arr.length; var swaps = true; while (gap > 1 || swaps) { gap /= 1.247330950103979; if (gap < 1) gap = 1.0; var i = 0; swaps = false; while (i + gap < arr.length) { var igap = ...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Eiffel
Eiffel
  class BOGO_SORT   feature   bogo_sort (ar: ARRAY [INTEGER]): ARRAY [INTEGER] -- Sorted array in ascending order. do from until is_sorted (ar) = True loop Result := shuffel (ar) end end   feature {NONE}   is_sorted (ar: ARRAY [INTEGER]): BOOLEAN -- Is 'ar' sorted in ascending order? ...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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
void gnome_sort(int *a, int n) { int i=1, j=2, t; # define swap(i, j) { t = a[i]; a[i] = a[j]; a[j] = t; } while(i < n) { if (a[i - 1] > a[i]) { swap(i - 1, i); if (--i) continue; } i = j++; } # undef swap }
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 ...
#11l
11l
F bead_sort(&a) V maxv = max(a) V beads = [0] * (maxv * a.len)   L(i) 0 .< a.len L(j) 0 .< a[i] beads[i * maxv + j] = 1   L(j) 0 .< maxv V sum = 0 L(i) 0 .< a.len sum += beads[i * maxv + j] beads[i * maxv + j] = 0   L(i) a.len - sum .< a.len beads[...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Ada
Ada
with Ada.Text_Io; use Ada.Text_Io;   procedure Cocktail_Sort_Test is procedure Cocktail_Sort (Item : in out String) is procedure Swap(Left, Right : in out Character) is Temp : Character := Left; begin Left := Right; Right := Temp; end Swap; Swapped : Boolean := Fals...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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
import std.stdio, std.algorithm;   void countingSort(int[] array, in size_t min, in size_t max) pure nothrow { auto count = new int[max - min + 1]; foreach (number; array) count[number - min]++;   size_t z = 0; foreach (i; min .. max + 1) while (count[i - min] > 0) { array[z]...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Icon_and_Unicon
Icon and Unicon
procedure main() #: demonstrate various ways to sort a list and string demosort(combsort,[3, 14, 1, 5, 9, 2, 6, 3],"qwerty") end   procedure combsort(X,op) #: return sorted X local gap,swapped,i   op := sortop(op,X) # select how and what we sort   swapp...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Elena
Elena
import extensions; import system'routines;   extension op { bogoSorter() { var list := self;   until (list.isAscendant()) { list := list.randomize(list.Length) };   ^ list } }   public program() { var list := new int[]{3, 4, 1, 8, 7, -2, 0};   cons...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Elixir
Elixir
defmodule Sort do def bogo_sort(list) do if sorted?(list) do list else bogo_sort(Enum.shuffle(list)) end end   defp sorted?(list) when length(list)<=1, do: true defp sorted?([x, y | _]) when x>y, do: false defp sorted?([_, y | rest]), do: sorted?([y | rest]) end
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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#
  public static void gnomeSort(int[] anArray) { int first = 1; int second = 2;   while (first < anArray.Length) { if (anArray[first - 1] <= anArray[first]) { first = second; second++; ...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 ...
#360_Assembly
360 Assembly
* Bead Sort 11/05/2016 BEADSORT CSECT USING BEADSORT,R13 base register SAVEAR B STM-SAVEAR(R15) skip savearea DC 17F'0' savearea STM STM R14,R12,12(R13) prolog ST R13,4(R15) " ST R15,8(R13) "...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program beadSort64.s */ /* En français tri par gravité ou tri par bille (ne pas confondre avec tri par bulle (bubble sort)) */   /*******************************************/ /* Constantes file */ /*******************************************/ ...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#ALGOL_60
ALGOL 60
begin comment Sorting algorithms/Cocktail sort - Algol 60; integer nA; nA:=20;   begin integer array A[1:nA];   procedure cocktailsort(lb,ub); value lb,ub; integer lb,ub; begin integer i,lbx,ubx; boolean swapped; lbx:=lb; ubx:=ub-1; sw...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#Delphi
Delphi
def countingSort(array, min, max) { def counts := ([0] * (max - min + 1)).diverge() for elem in array { counts[elem - min] += 1 } var i := -1 for offset => count in counts { def elem := min + offset for _ in 1..count { array[i += 1] := elem } } }
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Io
Io
List do( combSortInPlace := method( gap := size swap := true   while(gap > 1 or swap, swap = false gap = (gap / 1.25) floor   for(i, 0, size - gap, if(at(i) > at(i + gap), swap = true swapIndices(i, i...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Euphoria
Euphoria
function shuffle(sequence s) object temp integer j for i = length(s) to 1 by -1 do j = rand(i) if i != j then temp = s[i] s[i] = s[j] s[j] = temp end if end for return s end function   function inOrder(sequence s) for i = 1 to length(s)...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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++
g++ -std=c++11 gnome.cpp
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 ...
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program beadSort.s */ /* En français tri par gravité ou tri par bille (ne pas confondre avec tri par bulle (bubble sort) */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conver...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#ALGOL_68
ALGOL 68
MODE DATA = CHAR; PROC swap = (REF DATA a,b)VOID:( DATA tmp:=a; a:=b; b:=tmp );   PROC cocktail sort = (REF[]DATA a)VOID: ( WHILE BOOL swapped := FALSE; FOR i FROM LWB a TO UPB a - 1 DO IF a[ i ] > a[ i + 1 ] THEN # test whether the two elements are in the wrong order # swap( a[ i ], a[ i + 1 ...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#E
E
def countingSort(array, min, max) { def counts := ([0] * (max - min + 1)).diverge() for elem in array { counts[elem - min] += 1 } var i := -1 for offset => count in counts { def elem := min + offset for _ in 1..count { array[i += 1] := elem } } }
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#IS-BASIC
IS-BASIC
100 PROGRAM "CombSrt.bas" 110 RANDOMIZE 120 NUMERIC ARRAY(11 TO 30) 130 CALL INIT(ARRAY) 140 CALL WRITE(ARRAY) 150 CALL COMBSORT(ARRAY) 160 CALL WRITE(ARRAY) 170 DEF INIT(REF A) 180 FOR I=LBOUND(A) TO UBOUND(A) 190 LET A(I)=RND(98)+1 200 NEXT 210 END DEF 220 DEF WRITE(REF A) 230 FOR I=LBOUND(A) TO UBOUND(A) 2...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Factor
Factor
USING: grouping kernel math random sequences ;   : sorted? ( seq -- ? ) 2 <clumps> [ first2 <= ] all? ; : bogosort ( seq -- newseq ) [ dup sorted? ] [ randomize ] until ;
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Fantom
Fantom
  class Main { Bool in_order (Int[] items) { (0..<(items.size-1)).toList.all |Int i -> Bool| { items[i] <= items[i+1] } }   Int[] bogosort (Int[] items) { while (!in_order(items)) { items.shuffle } return items }   Void main () { // example echo ("Sorting ...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 gnomesort ([c] (gnomesort c <)) ([c pred] (loop [x [] [y1 & ys :as y] (seq c)] (cond (empty? y) x (empty? x) (recur (list y1) ys) true (let [zx (last x)] (if (pred y1 zx) (recur (butlast x) (concat (list y1 zx) ys)) ...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 ...
#Arturo
Arturo
beadSort: function [items][ a: new items m: neg infinity s: 0   loop a 'x [ if x > m -> m: x ]   beads: array.of: m * size a 0   loop 0..dec size a 'i [ loop 0..dec a\[i] 'j -> beads\[j + i * m]: 1 ]   loop 0..dec m 'j [ s: 0 loop 0..dec si...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#ALGOL_W
ALGOL W
begin  % As algol W does not allow overloading, we have to have type-specific  %  % sorting procedures - this coctail sorts an integer array  %  % as there is no way for the procedure to determine the array bounds, we %  % pass the lower and upper bounds in lb and ub  ...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#Eiffel
Eiffel
    class COUNTING_SORT   feature   sort (ar: ARRAY [INTEGER]; min, max: INTEGER): ARRAY [INTEGER] -- Sorted Array in ascending order. require ar_not_void: ar /= Void lowest_index_zero: ar.lower = 0 local count: ARRAY [INTEGER] i, j, z: INTEGER do create Result.make_empty Result.deep_copy (...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#J
J
combSort=:3 :0 gap=. #y whilst.1 < gap+swaps do. swaps=. 0 i=. i.2,gap=. 1 >. <.gap%1.25 while.{:$i=.i #"1~ ({: i) < #y do. swaps=.swaps+#{:k=.i #"1~b=. >/ i{y i=. i+gap y=.((|.k){y) k} y end. end. y )
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Fortran
Fortran
MODULE BOGO IMPLICIT NONE CONTAINS FUNCTION Sorted(a) LOGICAL :: Sorted INTEGER, INTENT(IN) :: a(:) INTEGER :: i   Sorted = .TRUE. DO i = 1, SIZE(a)-1 IF(a(i) > a(i+1)) THEN Sorted = .FALSE. EXIT END IF END DO END FUNCTION Sorted   SUBROUTINE SHUFFLE(a) IN...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#11l
11l
F bubble_sort(&seq) V changed = 1B L changed == 1B changed = 0B L(i) 0 .< seq.len - 1 I seq[i] > seq[i + 1] swap(&seq[i], &seq[i + 1]) changed = 1B   V testset = Array(0.<100) V testcase = copy(testset) random:shuffle(&testcase) assert(testcase != testset) bubble_sort(...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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-SORT SECTION. C-000. DISPLAY "SORT STARTING".   SET WB-IX-1 TO 2. MOVE 1 TO WC-NEXT-POSN.   PERFORM E-GNOME UNTIL WC-NEXT-POSN > WC-SIZE.   DISPLAY "SORT FINISHED".   C-999. EXIT.   E-GNOME SECTION. E-000. ...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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
BeadSort(data){ Pole:=[] , TempObj:=[], Result:=[] for, i, v in data { Row := i loop, % v MaxPole := MaxPole>A_Index?MaxPole:A_Index , Pole[A_Index, row] := 1 }   for i , obj in Pole { TempVar:=0 , c := A_Index for n, v in obj TempVar += v loop, % TempVar TempObj[c, A_Index] := 1 }   loop, % Ro...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program cocktailSort.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a f...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#Elena
Elena
import extensions; import system'routines;   extension op { countingSort() = self.clone().countingSort(self.MinimalMember, self.MaximalMember);   countingSort(int min, int max) { int[] count := new int[](max - min + 1); int z := 0;   count.populate:(int i => 0);   for...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#Elixir
Elixir
defmodule Sort do def counting_sort([]), do: [] def counting_sort(list) do {min, max} = Enum.min_max(list) count = Tuple.duplicate(0, max - min + 1) counted = Enum.reduce(list, count, fn x,acc -> i = x - min put_elem(acc, i, elem(acc, i) + 1) end) Enum.flat_map(min..max, &List.duplic...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Java
Java
public static <E extends Comparable<? super E>> void sort(E[] input) { int gap = input.length; boolean swapped = true; while (gap > 1 || swapped) { if (gap > 1) { gap = (int) (gap / 1.3); } swapped = false; for (int i = 0; i + gap < input.length; i++) { ...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#FreeBASIC
FreeBASIC
sub shuffle( a() as long ) dim as ulong n = ubound(a), i, j, k, m = ubound(a)*2 dim as ulong tmp randomize timer for k=1 to m i=int(rnd*n) j=int(rnd*n) tmp = a(i) a(i) = a(j) a(j) = tmp next k end sub   function inorder( a() as long ) as boolean dim as ul...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#360_Assembly
360 Assembly
* Bubble Sort 01/11/2014 & 23/06/2016 BUBBLE CSECT USING BUBBLE,R13,R12 establish base registers SAVEAREA B STM-SAVEAREA(R15) skip savearea DC 17F'0' my savearea STM STM R14,R12,12(R13) save calling context ST R13,4(R15) ...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 gnome-sort (array predicate &aux (length (length array))) (do ((position (min 1 length))) ((eql length position) array) (cond ((eql 0 position) (incf position)) ((funcall predicate (aref array position) (aref array (1- position))) (rotatef (aref arr...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 max(A, len) = valof $( let x = 0 for i=0 to len-1 if x<A!i do x := A!i resultis x $)   let beadsort(A, len) be $( let size = max(A, len) let tvec = getvec(size-1) for i=0 to size-1 do tvec!i := 0 for i=0 to len-1 for j=0 to A!i-1 do tvec!j := tvec!j + 1 for i...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 bead_sort(int *a, int len) { int i, j, max, sum; unsigned char *beads; # define BEAD(i, j) beads[i * max + j]   for (i = 1, max = a[0]; i < len; i++) if (a[i] > max) max = a[i];   beads = calloc(1, max * len);   /* mark the beads */ for (i = 0; i < len; i++) for (...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Arturo
Arturo
trySwap: function [arr,i][ if arr\[i] < arr\[i-1] [ tmp: arr\[i] arr\[i]: arr\[i-1] arr\[i-1]: tmp return null ] return true ] cocktailSort: function [items][ t: false l: size items while [not? t][ t: true loop 1..dec l 'i [ if null? tr...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#Fortran
Fortran
module CountingSort implicit none   interface counting_sort module procedure counting_sort_mm, counting_sort_a end interface   contains   subroutine counting_sort_a(array) integer, dimension(:), intent(inout) :: array   call counting_sort_mm(array, minval(array), maxval(array))   end subroutine c...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#JavaScript
JavaScript
  // Node 5.4.1 tested implementation (ES6) function is_array_sorted(arr) { var sorted = true; for (var i = 0; i < arr.length - 1; i++) { if (arr[i] > arr[i + 1]) { sorted = false; break; } } return sorted; }   // Array to sort var arr = ...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Gambas
Gambas
Public Sub Main() Dim sSorted As String = "123456789" 'The desired outcome Dim sTest, sChr As String 'Various strings Dim iCounter As Integer 'Loop counter   Do Inc iCounter 'Increase cou...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#6502_Assembly
6502 Assembly
define z_HL $00 define z_L $00 define z_H $01 define temp $02 define temp2 $03   set_table: dex txa sta $1200,y iny bne set_table ;stores $ff at $1200, $fe at $1201, etc.   lda #$12 sta z_H lda #$00 sta z_L   lda #0 tax tay ;clear regs   JSR BUBBLESORT BRK   BUBBLESORT: lda (z_HL),y sta temp iny ;look at the next i...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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
import std.stdio, std.algorithm;   void gnomeSort(T)(T arr) { int i = 1, j = 2; while (i < arr.length) { if (arr[i-1] <= arr[i]) { i = j; j++; } else { swap(arr[i-1], arr[i]); i--; if (i == 0) { i = j; j+...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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++
//this algorithm only works with positive, whole numbers. //O(2n) time complexity where n is the summation of the whole list to be sorted. //O(3n) space complexity.   #include <iostream> #include <vector>   using std::cout; using std::vector;   void distribute(int dist, vector<int> &List) { //*beads* go down into dif...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 % CocktailSort("") MsgBox % CocktailSort("xxx") MsgBox % CocktailSort("3,2,1") MsgBox % CocktailSort("dog,000000,xx,cat,pile,abcde,1,cat,zz,xx,z")   CocktailSort(var) { ; SORT COMMA SEPARATED LIST StringSplit array, var, `, ; make array i0 := 1, i1 := array0 ...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Function findMax(array() As Integer) As Integer Dim length As Integer = UBound(array) - LBound(array) + 1 If length = 0 Then Return 0 '' say If length = 1 Then Return array(LBound(array)) Dim max As Integer = LBound(array) For i As Integer = LBound(array) + 1 To UBound(array) If array...
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#jq
jq
# Input should be the array to be sorted. def combsort:   # As soon as "condition" is true, emit . and stop: def do_until(condition; next): def u: if condition then . else (next|u) end; u;   def swap(i;j): if i==j then . else .[i] as $tmp | .[i] = .[j] | .[j] = $tmp end;   . as $in | length as $len...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Go
Go
package main   import ( "fmt" "math/rand" "sort" "time" )   func main() { list := []int{31, 41, 59, 26, 53, 58, 97, 93, 23, 84} rand.Seed(time.Now().UnixNano()) fmt.Println("unsorted:", list) temp := make([]int, len(list)) copy(temp, list) for !sort.IntsAreSorted(temp) { ...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program bubbleSort64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly */ .include "../includeConstantesA...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#Delphi
Delphi
program TestGnomeSort;   {$APPTYPE CONSOLE}   {.$DEFINE DYNARRAY} // remove '.' to compile with dynamic array   type TItem = Integer; // declare ordinal type for array item {$IFDEF DYNARRAY} TArray = array of TItem; // dynamic array {$ELSE} TArray = array[0..15] of TItem; // static array {$ENDIF}   ...
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort
Sorting algorithms/Bead 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 transpose [xs] (loop [ret [], remain xs] (if (empty? remain) ret (recur (conj ret (map first remain)) (filter not-empty (map rest remain))))))   (defn bead-sort [xs] (->> xs (map #(repeat % 1)) transpose transpose (map #(reduce + %))))   ;; This alg...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#AWK
AWK
{ line[NR] = $0 } END { # sort it with cocktail sort swapped = 0 do { for(i=1; i < NR; i++) { if ( line[i] > line[i+1] ) { t = line[i] line[i] = line[i+1] line[i+1] = t swapped = 1 } } if ( swapped == 0 ) break swapped = 0 for(i=NR-1; i >= 1; i--) { if ( line[i] > line[i+...
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort
Sorting algorithms/Counting 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 ...
#Go
Go
package main   import ( "fmt" "runtime" "strings" )   var a = []int{170, 45, 75, -90, -802, 24, 2, 66} var aMin, aMax = -1000, 1000   func main() { fmt.Println("before:", a) countingSort(a, aMin, aMax) fmt.Println("after: ", a) }   func countingSort(a []int, aMin, aMax int) { defer func() { ...
http://rosettacode.org/wiki/Sort_using_a_custom_comparator
Sort using a custom comparator
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 ...
#11l
11l
V strings = ‘here are Some sample strings to be sorted’.split(‘ ’)   print(sorted(strings, key' x -> (-x.len, x.uppercase())))
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
Sorting algorithms/Comb sort
Sorting algorithms/Comb sort You are encouraged to solve this task according to the task description, using any language you may know. 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 algor...
#Julia
Julia
# v0.6   function combsort!(x::Array)::Array gap, swaps = length(x), true while gap > 1 || swaps gap = floor(Int, gap / 1.25) i, swaps = 0, false while i + gap < length(x) if x[i+1] > x[i+1+gap] x[i+1], x[i+1+gap] = x[i+1+gap], x[i+1] swaps = t...
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort
Sorting algorithms/Bogosort
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 ...
#Groovy
Groovy
def bogosort = { list -> def n = list.size() while (n > 1 && (1..<n).any{ list[it-1] > list[it] }) { print '.'*n Collections.shuffle(list) } list }
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#ACL2
ACL2
(defun bubble (xs) (if (endp (rest xs)) (mv nil xs) (let ((x1 (first xs)) (x2 (second xs))) (if (> x1 x2) (mv-let (_ ys) (bubble (cons x1 (rest (rest xs)))) (declare (ignore _)) (mv t (cons x2 ys))) (mv...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#DWScript
DWScript
procedure GnomeSort(a : array of Integer); var i, j : Integer; begin i := 1; j := 2; while i < a.Length do begin if a[i-1] <= a[i] then begin i := j; j := j + 1; end else begin a.Swap(i-1, i); i := i - 1; if i = 0 then begin i := j; ...