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/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
... | #CLU | CLU | % Bubble-sort an array in place.
bubble_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 hi: int in int$from_to_by(bound_hi, bound_lo, -1) do
for i: int in int$from_to(bound_lo... |
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
... | #IS-BASIC | IS-BASIC |
100 PROGRAM "GnomeSrt.bas"
110 RANDOMIZE
120 NUMERIC ARRAY(-5 TO 12)
130 CALL INIT(ARRAY)
140 CALL WRITE(ARRAY)
150 CALL GNOMESORT(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(... |
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
... | #OpenEdge.2FProgress | OpenEdge/Progress | FUNCTION beadSort RETURNS CHAR (
i_c AS CHAR
):
DEF VAR cresult AS CHAR.
DEF VAR ii AS INT.
DEF VAR inumbers AS INT.
DEF VAR irod AS INT.
DEF VAR irods AS INT.
DEF VAR crod AS CHAR.
DEF VAR cbeads AS CHAR EXTENT.
inumbers = NUM-ENTRIES( i_c ).
/* determine ... |
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
... | #PARI.2FGP | PARI/GP | beadsort(v)={
my(sz=vecmax(v),M=matrix(#v,sz,i,j,v[i]>=j)); \\ Set up beads
for(i=1,sz,M[,i]=countingSort(M[,i],0,1)~); \\ Let them fall
vector(#v,i,value(M[i,])) \\ Convert back to numbers
};
countingSort(v,mn,mx)={
my(u=vector(#v),i=0);
for(n=mn,mx,
for(j=1,#v,if(v[j]==n,u[i++]=n... |
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
... | #Haskell | Haskell | cocktailSort :: Ord a => [a] -> [a]
cocktailSort l
| not swapped1 = l
| not swapped2 = reverse $ l1
| otherwise = cocktailSort l2
where (swapped1, l1) = swappingPass (>) (False, []) l
(swapped2, l2) = swappingPass (<) (False, []) l1
swappingPass :: Ord a => (a -> a -> Bool) -> (Bool, [a]) -... |
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
... | #Pascal | Pascal | program CountingSort;
procedure counting_sort(var arr : Array of Integer; n, min, max : Integer);
var
count : Array of Integer;
i, j, z : Integer;
begin
SetLength(count, max-min);
for i := 0 to (max-min) do
count[i] := 0;
for i := 0 to (n-1) do
count[ arr[i] - min ] := count[ arr[i] - min... |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
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 | CO PR READ "shell_sort.a68" PR CO
MODE TYPE = INT;
PROC in place shell sort = (REF[]TYPE seq)REF[]TYPE:(
INT inc := ( UPB seq + LWB seq + 1 ) OVER 2;
WHILE inc NE 0 DO
FOR index FROM LWB seq TO UPB seq DO
INT i := index;
TYPE el = seq[i];
WHILE ( i - LWB seq >= inc... |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
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! | DEFINE PTR="CARD"
PROC PrintArray(PTR ARRAY a INT size)
INT i
FOR i=0 TO size-1
DO
PrintE(a(i))
OD
RETURN
INT FUNC Decode(CHAR ARRAY s INT ARRAY a)
INT count
BYTE i,begin,end
CHAR ARRAY tmp(10)
count=0 i=1
WHILE i<=s(0)
DO
begin=i
WHILE i<=s(0) AND s(i)#'.
DO i==+1 OD
end... |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
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.Containers.Generic_Array_Sort;
with Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO;
with Ada.Unchecked_Deallocation;
procedure Sort_List_Identifiers is
type Natural_Array is array (Positive range <>) of Natural;
type Unbounded_String_Array is array(Positive r... |
http://rosettacode.org/wiki/Sort_disjoint_sublist | Sort disjoint sublist |
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>
/* yes, bubble sort */
void bubble_sort(int *idx, int n_idx, int *buf)
{
int i, j, tmp;
#define for_ij for (i = 0; i < n_idx; i++) for (j = i + 1; j < n_idx; j++)
#define sort(a, b) if (a < b) { tmp = a; a = b; b = tmp;}
for_ij { sort(idx[j], idx[i]); }
for_ij { sor... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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
... | #J | J | import java.util.Arrays;
import java.util.Comparator;
public class RJSortStability {
public static void main(String[] args) {
String[] cityList = { "UK London", "US New York", "US Birmingham", "UK Birmingham", };
String[] cn = cityList.clone();
System.out.println("\nBefore sort:");
for (Stri... |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 | (println
(by
format
sort
(range 1 13) ) ) |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 | lexicographical_sort(Numbers, Sorted_numbers):-
number_strings(Numbers, Strings),
sort(Strings, Sorted_strings),
number_strings(Sorted_numbers, Sorted_strings).
number_strings([], []):-!.
number_strings([Number|Numbers], [String|Strings]):-
number_string(Number, String),
number_strings(Numbers, St... |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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
... | #IS-BASIC | IS-BASIC | 100 LET X=77444:LET Y=-12:LET Z=0
110 PRINT X;Y;Z
120 CALL SHORT(X,Y,Z)
130 PRINT X;Y;Z
140 DEF SHORT(REF A,REF B,REF C)
150 IF A>B THEN LET T=A:LET A=B:LET B=T
160 IF B>C THEN LET T=B:LET B=C:LET C=T
170 IF A>B THEN LET T=A:LET A=B:LET B=T
180 END DEF |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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
... | #J | J | x =: 'lions, tigers, and'
y =: 'bears, oh my!'
z =: '(from the "Wizard of OZ")'
'x y z'=: /:~".'x;y;<z'
x
(from the "Wizard of OZ")
y
bears, oh my!
z
lions, tigers, and
x =: 77444
y =: -12
z =: 0
'x y z'=: /:~".'x;y;<z'
x
_12
y
0
z
77444 |
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
... | #Factor | Factor | : my-compare ( s1 s2 -- <=> )
2dup [ length ] compare invert-comparison
dup +eq+ = [ drop [ >lower ] compare ] [ 2nip ] if ;
{ "this" "is" "a" "set" "of" "strings" "to" "sort" } [ my-compare ] sort |
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... | #PureBasic | PureBasic | ;sorts an array of integers
Procedure combSort11(Array a(1))
Protected i, gap, swaps = 1
Protected nElements = ArraySize(a())
gap = nElements
While (gap > 1) Or (swapped = 1)
gap * 10 / 13
If gap = 9 Or gap = 10: gap = 11: EndIf
If gap < 1: gap = 1: EndIf
i = 0
swaps = 0
While (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
... | #PARI.2FGP | PARI/GP | bogosort(v)={
while(1,
my(u=vecextract(v,numtoperm(#v,random((#v)!))));
for(i=2,#v,if(u[i]<u[i-1], next(2)));
return(u)
);
}; |
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
... | #CMake | CMake | # bubble_sort(var [value1 value2...]) sorts a list of integers.
function(bubble_sort var)
math(EXPR last "${ARGC} - 1") # Prepare to sort ARGV[1]..ARGV[last].
set(again YES)
while(again)
set(again NO)
math(EXPR last "${last} - 1") # Decrement last index.
foreach(index RANGE 1 ${last}) ... |
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
... | #J | J | position=: 0 {.@I.@, [
swap=: ] A.~ *@position * #@[ !@- <:@position
gnome=: swap~ 2 >/\ ]
gnomes=: gnome^:_ |
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
... | #Pascal | Pascal |
program BDS;
const MAX = 1000;
type
type_matrix = record
lin,col:integer;
matrix: array [1..MAX,1..MAX] of boolean;
end;
type_vector = record
size:integer;
vector: array[1..MAX] of integer;
end;
procedure BeadSort(var v:type_vector);
var
i,j,k,sum:integer;
m:type_matrix;
begin
m.l... |
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
... | #Ksh | Ksh | #!/bin/ksh
# cocktail shaker sort
# # Variables:
#
integer TRUE=1
integer FALSE=0
typeset -a arr=( 5 -1 101 -4 0 1 8 6 2 3 )
# # Functions:
#
function _swap {
typeset _i ; integer _i=$1
typeset _j ; integer _j=$2
typeset _array ; nameref _array="$3"
typeset _swapped ; nameref _swapped=$4
typeset _tmp ; _tm... |
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
... | #Perl | Perl | #! /usr/bin/perl
use strict;
sub counting_sort
{
my ($a, $min, $max) = @_;
my @cnt = (0) x ($max - $min + 1);
$cnt[$_ - $min]++ foreach @$a;
my $i = $min;
@$a = map {($i++) x $_} @cnt;
} |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
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
% use the quicksort procedure from the Sorting_Algorithms/Quicksort task %
% Quicksorts in-place the array of integers v, from lb to ub - external %
procedure quicksort ( integer array v( * )
; integer value lb, ub
) ; algol "sortingAlgorithms_Quicksort... |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
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
... | #APL | APL | X←63 92 51 92 39 15 43 89 36 69
X[⍋X]
15 36 39 43 51 63 69 89 92 92 |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
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
... | #AppleScript | AppleScript | (* Shell sort
Algorithm: Donald Shell, 1959.
*)
on ShellSort(theList, l, r)
script o
property lst : theList
end script
set listLength to (count theList)
if (listLength > 1) then
-- Convert negative and/or transposed range indices.
if (l < 0) then set l to listLength + l + 1
... |
http://rosettacode.org/wiki/Sort_disjoint_sublist | Sort disjoint sublist |
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;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
var list = new List<int>{ 7, 6, 5, 4, 3, 2, 1, 0 };
list.SortSublist(6, 1, 7);
Console.WriteLine(string.Join(", ", list));
}
}
public static class Extensions
{
p... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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
... | #Java | Java | import java.util.Arrays;
import java.util.Comparator;
public class RJSortStability {
public static void main(String[] args) {
String[] cityList = { "UK London", "US New York", "US Birmingham", "UK Birmingham", };
String[] cn = cityList.clone();
System.out.println("\nBefore sort:");
for (Stri... |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 | EnableExplicit
Procedure lexOrder(n, Array ints(1))
Define first = 1, last = n, k = n, i
If n < 1
first = n
last = 1
k = 2 - n
EndIf
Dim strs.s(k - 1)
For i = first To last
strs(i - first) = Str(i)
Next
SortArray(strs(), #PB_Sort_Ascending)
For i = 0 T... |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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
... | #Java | Java |
import java.util.Comparator;
import java.util.stream.Stream;
class Box {
public int weightKg;
Box(final int weightKg) {
this.weightKg = weightKg;
}
}
public class Sort3Vars {
public static void main(String... args) {
int iA = 21;
int iB = 11;
int iC = 82;
... |
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
... | #Fantom | Fantom |
class Main
{
public static Void main ()
{
// sample strings from Lisp example
strs := ["Cat", "apple", "Adam", "zero", "Xmas", "quit",
"Level", "add", "Actor", "base", "butter"]
sorted := strs.dup // make a copy of original list
sorted.sort |Str a, Str b -> Int| // sort using cus... |
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... | #Python | Python | >>> def combsort(input):
gap = len(input)
swaps = True
while gap > 1 or swaps:
gap = max(1, int(gap / 1.25)) # minimum gap is 1
swaps = False
for i in range(len(input) - gap):
j = i+gap
if input[i] > input[j]:
input[i], input[j] = input[j], in... |
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
... | #Pascal | Pascal | program bogosort;
const
max = 5;
type
list = array [1..max] of integer;
{ Print a list }
procedure printa(a: list);
var
i: integer;
begin
for i := 1 to max do
write(a[i], ' ');
writeln
end;
{ Knuth shuffle }
procedure shuffle(var a: list);
var
i,k,tmp: integer;
begin
for i := max downto 2 do beg... |
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
... | #COBOL | COBOL |
IDENTIFICATION DIVISION.
PROGRAM-ID. BUBBLESORT.
AUTHOR. DAVE STRATFORD.
DATE-WRITTEN. MARCH 2010.
INSTALLATION. HEXAGON SYSTEMS LIMITED.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
... |
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
... | #Java | Java | public static void gnomeSort(int[] a)
{
int i=1;
int j=2;
while(i < a.length) {
if ( a[i-1] <= a[i] ) {
i = j; j++;
} else {
int tmp = a[i-1];
a[i-1] = a[i];
a[i--] = tmp;
i = (i==0) ? j++ : 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
... | #Perl | Perl | sub beadsort {
my @data = @_;
my @columns;
my @rows;
for my $datum (@data) {
for my $column ( 0 .. $datum-1 ) {
++ $rows[ $columns[$column]++ ];
}
}
return reverse @rows;
}
beadsort 5, 7, 1, 3, 1, 1, 20;
|
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
... | #Haxe | Haxe | class CocktailSort {
@:generic
public static function sort<T>(arr:Array<T>) {
var swapped = false;
do {
swapped = false;
for (i in 0...(arr.length - 1)) {
if (Reflect.compare(arr[i], arr[i + 1]) > 0) {
var temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tem... |
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
... | #Phix | Phix | with javascript_semantics
function countingSort(sequence array, integer mina, maxa)
sequence count = repeat(0,maxa-mina+1)
array = deep_copy(array)
for i=1 to length(array) do
count[array[i]-mina+1] += 1
end for
integer z = 1
for i=mina to maxa do
for j=1 to count[i-mina+1] do
... |
http://rosettacode.org/wiki/Solve_a_Numbrix_puzzle | Solve a Numbrix puzzle | Numbrix puzzles are similar to Hidato.
The most important difference is that it is only possible to move 1 node left, right, up, or down (sometimes referred to as the Von Neumann neighborhood).
Published puzzles also tend not to have holes in the grid and may not always indicate the end node.
Two examples follow:
Exam... | #11l | 11l | V neighbours = [[-1, 0], [0, -1], [1, 0], [0, 1]]
[Int] exists
V lastNumber = 0
V wid = 0
V hei = 0
F find_next(pa, x, y, z)
L(i) 4
V a = x + :neighbours[i][0]
V b = y + :neighbours[i][1]
I a C -1 <.< :wid & b C -1 <.< :hei
I pa[a][b] == z
R (a, b)
R (-1, -1)
F find_solu... |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
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
... | #AppleScript | AppleScript | use framework "Foundation"
-- sort :: [a] -> [a]
on sort(lst)
((current application's NSArray's arrayWithArray:lst)'s ¬
sortedArrayUsingSelector:"compare:") as list
end sort
-- TEST -----------------------------------------------------------------------
on run
map(sort, [[9, 1, 8, 2, 8, 3, 7, 0, 4... |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
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 | ; based on http://www.rosettacode.org/wiki/Sorting_algorithms/Quicksort#AutoHotkey
OidQuickSort(a, Delim:=".", index:=1){
if (a.Count() <= 1)
return a
Less := [], Equal := [], More := []
Pivot := StrSplit(a[1], Delim)[index]
for k, v in a
{
x := StrSplit(v, Delim)[index]
if (... |
http://rosettacode.org/wiki/Sort_disjoint_sublist | Sort disjoint sublist |
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 <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
template <typename ValueIterator, typename IndicesIterator>
void sortDisjoint(ValueIterator valsBegin, IndicesIterator indicesBegin,
IndicesIterator indicesEnd) {
std::vector<int> temp;
for (IndicesIterator i = indicesBegin; ... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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
... | #JavaScript | JavaScript | ary = [["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]
print(ary);
ary.sort(function(a,b){return (a[1]<b[1] ? -1 : (a[1]>b[1] ? 1 : 0))});
print(ary);
/* a stable sort will output ["US", "Birmingham"] before ["UK", "Birmingham"] */ |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 | [["UK", "London"],
["US", "New York"],
["US", "Birmingham"],
["UK", "Birmingham"]]
| sort_by(.[1]) |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 | n=13
print(sorted(range(1,n+1), key=str)) |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 | [ [] swap times
[ i^ 1+ number$
nested join ]
sort$
[] swap
witheach
[ $->n drop join ] ] is task ( n --> [ )
13 task echo |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 (lex-sort n) (sort (if (< 0 n) (range 1 (add1 n)) (range n 2))
string<? #:key number->string))
(define (show n) (printf "~a: ~a\n" n (lex-sort n)))
(show 0)
(show 1)
(show 5)
(show 13)
(show 21)
(show -22) |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 lex (Real $n, $step = 1) {
($n < 1 ?? ($n, * + $step …^ * > 1)
!! ($n, * - $step …^ * < 1)).sort: ~*
}
# TESTING
for 13, 21, -22, (6, .333), (-4, .25), (-5*π, e) {
my ($bound, $step) = |$_, 1;
say "Boundary:$bound, Step:$step >> ", lex($bound, $step).join: ', ';
} |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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
... | #JavaScript | JavaScript | const printThree = (note, [a, b, c], [a1, b1, c1]) => {
console.log(`${note}
${a} is: ${a1}
${b} is: ${b1}
${c} is: ${c1}
`);
};
const sortThree = () => {
let a = 'lions, tigers, and';
let b = 'bears, oh my!';
let c = '(from the "Wizard of OZ")';
printThree('Before Sorting', ['a', 'b', 'c'], [... |
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
... | #Fortran | Fortran | module sorts_with_custom_comparator
implicit none
contains
subroutine a_sort(a, cc)
character(len=*), dimension(:), intent(inout) :: a
interface
integer function cc(a, b)
character(len=*), intent(in) :: a, b
end function cc
end interface
integer :: i, j, increment
charac... |
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... | #R | R |
comb.sort<-function(a){
gap<-length(a)
swaps<-1
while(gap>1 & swaps==1){
gap=floor(gap/1.3)
if(gap<1){
gap=1
}
swaps=0
i=1
while(i+gap<=length(a)){
if(a[i]>a[i+gap]){
a[c(i,i+gap)] <- a[c(i+gap,i)]
swaps=1
}
i<-i+1
}
}
return(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
... | #Perl | Perl | use List::Util qw(shuffle);
sub bogosort
{my @l = @_;
@l = shuffle(@l) until in_order(@l);
return @l;}
sub in_order
{my $last = shift;
foreach (@_)
{$_ >= $last or return 0;
$last = $_;}
return 1;} |
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
... | #Common_Lisp | Common Lisp | (defun bubble-sort (sequence &optional (compare #'<))
"sort a sequence (array or list) with an optional comparison function (cl:< is the default)"
(loop with sorted = nil until sorted do
(setf sorted t)
(loop for a below (1- (length sequence)) do
(unless (funcall compare (elt sequence ... |
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
... | #JavaScript | JavaScript | function gnomeSort(a) {
function moveBack(i) {
for( ; i > 0 && a[i-1] > a[i]; i--) {
var t = a[i];
a[i] = a[i-1];
a[i-1] = t;
}
}
for (var i = 1; i < a.length; i++) {
if (a[i-1] > a[i]) moveBack(i);
}
return a;
} |
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
... | #Phix | Phix | with javascript_semantics
function beadsort(sequence a)
sequence poles = repeat(0,max(a))
for i=1 to length(a) do
poles[1..a[i]] = sq_add(poles[1..a[i]],1)
end for
a[1..$] = 0
for i=1 to length(poles) do
a[1..poles[i]] = sq_add(a[1..poles[i]],1)
end for
return a
end function... |
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
... | #Icon_and_Unicon | Icon and Unicon | procedure main() #: demonstrate various ways to sort a list and string
demosort(cocktailsort,[3, 14, 1, 5, 9, 2, 6, 3],"qwerty")
end
procedure cocktailsort(X,op) #: return sorted list
local i,swapped
op := sortop(op,X) # select how and what we sort
swapped :... |
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures | Sort an array of composite structures |
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 | T Employee
String name, category
F (name, category)
.name = name
.category = category
V employees = [
Employee(‘David’, ‘Manager’),
Employee(‘Alice’, ‘Sales’),
Employee(‘Joanna’, ‘Director’),
Employee(‘Henry’, ‘Admin’),
Employee(‘Tim’, ‘Sales’),
Employee(‘Juan’, ‘Admin’)
]
empl... |
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
... | #PHP | PHP | <?php
function counting_sort(&$arr, $min, $max)
{
$count = array();
for($i = $min; $i <= $max; $i++)
{
$count[$i] = 0;
}
foreach($arr as $number)
{
$count[$number]++;
}
$z = 0;
for($i = $min; $i <= $max; $i++) {
while( $count[$i]-- > 0 ) {
$arr[$z++] = $i;
}
}
} |
http://rosettacode.org/wiki/Solve_a_Numbrix_puzzle | Solve a Numbrix puzzle | Numbrix puzzles are similar to Hidato.
The most important difference is that it is only possible to move 1 node left, right, up, or down (sometimes referred to as the Von Neumann neighborhood).
Published puzzles also tend not to have holes in the grid and may not always indicate the end node.
Two examples follow:
Exam... | #AutoHotkey | AutoHotkey | SolveNumbrix(Grid, Locked, Max, row, col, num:=1, R:="", C:=""){
if (R&&C) ; if neighbors (not first iteration)
{
Grid[R, C] := ">" num ; place num in current neighbor and mark it visited ">"
row:=R, col:=C ; move to current neighbor
}
num++ ; increment num
if (num=max) ; if reac... |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
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 integerSort.s with selection sort */
/* 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... |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
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 |
# syntax: GAWK -f SORT_A_LIST_OF_OBJECT_IDENTIFIERS.AWK
#
# sorting:
# PROCINFO["sorted_in"] is used by GAWK
# SORTTYPE is used by Thompson Automation's TAWK
#
BEGIN {
width = 10
oid_arr[++n] = "1.3.6.1.4.1.11.2.17.19.3.4.0.10"
oid_arr[++n] = "1.3.6.1.4.1.11.2.17.5.2.0.79"
oid_arr[++n] = "1.3.6.1.... |
http://rosettacode.org/wiki/Sort_disjoint_sublist | Sort disjoint sublist |
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 disjoint-sort [coll idxs]
(let [val-subset (keep-indexed #(when ((set idxs) %) %2) coll)
replacements (zipmap (set idxs) (sort val-subset))]
(apply assoc coll (flatten (seq replacements))))) |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 | julia> A = [("UK", "London"), ("US", "New York"), ("US", "Birmingham"), ("UK", "Birmingham")];
julia> sort(A, by=x -> x[2])
4-element Array{(ASCIIString,ASCIIString),1}:
("US","Birmingham")
("UK","Birmingham")
("UK","London")
("US","New York")
|
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 | // version 1.1.51
fun main(args: Array<String>) {
val cities = listOf("UK London", "US New York", "US Birmingham", "UK Birmingham")
println("Original : $cities")
// sort by country
println("By country : ${cities.sortedBy { it.take(2) } }")
// sort by city
println("By city : ${cities.sorte... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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
... | #Lasso | Lasso | //Single param array:
array->sort
//An array of pairs, order by the right hand element of the pair:
with i in array order by #i->second do => { … }
//The array can also be ordered by multiple values:
with i in array order by #i->second, #i->first do => { … } |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 pgm displays a horizontal list of a range of numbers sorted lexicographically.*/
parse arg LO HI INC . /*obtain optional arguments from the CL*/
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/
if HI=='' | HI=="," then HI= 13 ... |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 |
# Project : Lexicographical numbers
lex = 1:13
strlex = list(len(lex))
for n = 1 to len(lex)
strlex[n] = string(lex[n])
next
strlex = sort(strlex)
see "Lexicographical numbers = "
showarray(strlex)
func showarray(vect)
see "["
svect = ""
for n = 1 to len(vect)
svect = sv... |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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 | def example1:
{x: "lions, tigers, and",
y: "bears, oh my",
z: "(from the \"Wizard of OZ\")"
};
def example2:
{x: 77444,
y: -12,
z: 0
}; |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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
... | #Jsish | Jsish | #!/usr/bin/env jsish
/* Sort three variables, in Jsish. semi-colon start/end for unit test echo */
var x = 'lions, tigers, and';
var y = 'bears, oh my!';
var z = '(from the "Wizard of OZ")';
var arr = [x,y,z];
arr = arr.sort();
;'As strings, before:';
;x;
;y;
;z;
x = arr.shift();
y = arr.shift();
z = arr.shi... |
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
... | #FreeBASIC | FreeBASIC | ' version 23-10-2016
' compile with: fbc -s console
#Include Once "crt/stdlib.bi" ' for qsort
Function mycmp Cdecl (s1 As Any Pointer, s2 As Any Pointer) As Long
' -1 no swap first element before second element
' 0 no swap needed, don't care
' 1 swap first element after second element
Dim As S... |
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... | #Racket | Racket |
#lang racket
(require (only-in srfi/43 vector-swap!))
(define (comb-sort xs)
(define (ref i) (vector-ref xs i))
(define (swap i j) (vector-swap! xs i j))
(define (new gap) (max 1 (exact-floor (/ gap 1.25))))
(define size (vector-length xs))
(let loop ([gap size] [swaps 0])
(unless (and (= gap 1) (= ... |
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
... | #Phix | Phix | with javascript_semantics
function inOrder(sequence s)
return s==sort(deep_copy(s)) -- <snigger>
end function
function bogosort(sequence s)
while not inOrder(s) do
? s
s = shuffle(s)
end while
return s
end function
? bogosort(shuffle({1,2,3,4,5,6}))
|
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
... | #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);
# Bubble sort an array of pointer-sized integers given a comparator function
# (This is the close... |
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
... | #jq | jq | # As soon as "condition" is true, then emit . and stop:
def do_until(condition; next):
def u: if condition then . else (next|u) end;
u;
# input: an array
def gnomeSort:
def swap(i;j): .[i] as $x | .[i]=.[j] | .[j]=$x;
length as $length
# state: [i, j, ary]
| [1, 2, .]
| do_until( .[0] >= $length;
... |
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
... | #PHP | PHP | <?php
function columns($arr) {
if (count($arr) == 0)
return array();
else if (count($arr) == 1)
return array_chunk($arr[0], 1);
array_unshift($arr, NULL);
// array_map(NULL, $arr[0], $arr[1], ...)
$transpose = call_user_func_array('array_map', $arr);
return array_map('array_fil... |
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
... | #Io | Io | List do (
cocktailSortInPlace := method(
start := 0
end := size - 2
loop(
swapped := false
for(idx, start, end,
if(at(idx) > at(idx + 1),
swapped := true
swapIndices(idx, idx + 1)
)
... |
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures | Sort an array of composite structures |
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 shellSort64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesAR... |
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures | Sort an array of composite structures |
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 insert-by-key (o os key)
(cond ((endp os) (list o))
((< (cdr (assoc key o))
(cdr (assoc key (first os))))
(cons o os))
(t (cons (first os)
(insert-by-key o (rest os) key)))))
(defun isort-by-key (os key)
(if (endp os)
nil
(insert-by... |
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
... | #PicoLisp | PicoLisp | (de countingSort (Lst Min Max)
(let Count (need (- Max Min -1) 0)
(for N Lst
(inc (nth Count (- N Min -1))) )
(make
(map
'((C I)
(do (car C) (link (car I))) )
Count
(range Min Max) ) ) ) ) |
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
... | #PL.2FI | PL/I | count_sort: procedure (A);
declare A(*) fixed;
declare (min, max) fixed;
declare i fixed binary;
max, min = A(lbound(A,1));
do i = 1 to hbound(A,1);
if max < A(i) then max = A(i);
if min > A(i) then min = A(i);
end;
begin;
declare t(min:max) fixed;
declare (i, j, k) fi... |
http://rosettacode.org/wiki/Solve_a_Numbrix_puzzle | Solve a Numbrix puzzle | Numbrix puzzles are similar to Hidato.
The most important difference is that it is only possible to move 1 node left, right, up, or down (sometimes referred to as the Von Neumann neighborhood).
Published puzzles also tend not to have holes in the grid and may not always indicate the end node.
Two examples follow:
Exam... | #C.23 | C# | using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using static System.Linq.Enumerable;
public class Solver
{
private static readonly (int dx, int dy)[]
//other puzzle types elided
numbrixMoves = {(1,0),(0,1),(-1,0),(0,-1)};
pri... |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
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 | arr: [2 3 5 8 4 1 6 9 7]
sort 'arr ; in-place
loop arr => print |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
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 | numbers = 5 4 1 2 3
sort, numbers, N D%A_Space%
Msgbox % numbers |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
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>
#include <string.h>
typedef struct oid_tag {
char* str_;
int* numbers_;
int length_;
} oid;
// free memory, no-op if p is null
void oid_destroy(oid* p) {
if (p != 0) {
free(p->str_);
free(p->numbers_);
free(p);
}
}
int char_count(c... |
http://rosettacode.org/wiki/Sort_disjoint_sublist | Sort disjoint sublist |
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 disjoint-sort (values indices)
"Destructively perform a disjoin sublist sort on VALUES with INDICES."
(loop :for element :in
(sort (loop :for index :across indices
:collect (svref values index))
'<)
:for index :across (sort indices '<)
:do (setf (svref values index) el... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 |
randomize 0.5
N=15
dim a(N,2)
for i = 0 to N-1
a(i,1)= int(i/5)
a(i,2)= int(rnd(1)*5)
next
print "Unsorted by column #2"
print "by construction sorted by column #1"
for i = 0 to N-1
print a(i,1), a(i,2)
next
sort a(), 0, N-1, 2
print
print "After sorting by column #2"
print "Notice wrong order by ... |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 | n = 13
p (1..n).sort_by(&:to_s)
|
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 lex_sorted_vector(num: i32) -> Vec<i32> {
let (min, max) = if num >= 1 { (1, num) } else { (num, 1) };
let mut str: Vec<String> = (min..=max).map(|i| i.to_string()).collect();
str.sort();
str.iter().map(|s| s.parse::<i32>().unwrap()).collect()
}
fn main() {
for n in &[0, 5, 13, 21, -22] {
... |
http://rosettacode.org/wiki/Sort_numbers_lexicographically | Sort numbers lexicographically |
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 LexicographicalNumbers extends App { def ints = List(0, 5, 13, 21, -22)
def lexOrder(n: Int): Seq[Int] = (if (n < 1) n to 1 else 1 to n).sortBy(_.toString)
println("In lexicographical order:\n")
for (n <- ints) println(f"$n%3d: ${lexOrder(n).mkString("[",", ", "]")}%s")
} |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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 | # v0.6
a, b, c = "lions, tigers, and", "bears, oh my!", "(from the \"Wizard of OZ\")"
a, b, c = sort([a, b, c])
@show a b c
a, b, c = 77444, -12, 0
a, b, c = sort([a, b, c])
@show a b c |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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 | // version 1.1.2
inline fun <reified T : Comparable<T>> sortThree(x: T, y: T, z: T): Triple<T, T, T> {
val a = arrayOf(x, y, z)
a.sort()
return Triple(a[0], a[1], a[2])
}
fun <T> printThree(x: T, y: T, z: T) = println("x = $x\ny = $y\nz = $z\n")
fun main(args: Array<String>) {
var x = "lions, tige... |
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
... | #Frink | Frink | f = {|a,b|
len = length[b] <=> length[a]
if len != 0
return len
else
return lexicalCompare[a,b]
}
words = split[%r/\s+/, "Here are some sample strings to be sorted"]
println[sort[words, f]] |
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... | #Raku | Raku | sub comb_sort ( @a is copy ) {
my $gap = +@a;
my $swaps = 1;
while $gap > 1 or $swaps {
$gap = ( ($gap * 4) div 5 ) || 1 if $gap > 1;
$swaps = 0;
for ^(+@a - $gap) -> $i {
my $j = $i + $gap;
if @a[$i] > @a[$j] {
@a[$i, $j] .= reverse;
... |
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
... | #PHP | PHP | function bogosort($l) {
while (!in_order($l))
shuffle($l);
return $l;
}
function in_order($l) {
for ($i = 1; $i < count($l); $i++)
if ($l[$i] < $l[$i-1])
return FALSE;
return TRUE;
} |
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
... | #D | D | import std.stdio, std.algorithm : swap;
T[] bubbleSort(T)(T[] data) pure nothrow
{
foreach_reverse (n; 0 .. data.length)
{
bool swapped;
foreach (i; 0 .. n)
if (data[i] > data[i + 1]) {
swap(data[i], data[i + 1]);
swapped = true;
}
... |
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
... | #Julia | Julia | function gnomesort!(arr::Vector)
i, j = 1, 2
while i < length(arr)
if arr[i] ≤ arr[i+1]
i = j
j += 1
else
arr[i], arr[i+1] = arr[i+1], arr[i]
i -= 1
if i == 0
i = j
j += 1
end
end
... |
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
... | #PicoLisp | PicoLisp | (de beadSort (Lst)
(let Abacus (cons NIL)
(for N Lst # Thread beads on poles
(for (L Abacus (ge0 (dec 'N)) (cdr L))
(or (cdr L) (queue 'L (cons)))
(push (cadr L) T) ) )
(make
(while (gt0 (cnt pop (cdr Abacus))) # Drop and... |
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
... | #PL.2FI | PL/I |
/* Handles both negative and positive values. */
maxval: procedure (z) returns (fixed binary);
declare z(*) fixed binary;
declare (maxv initial (0), i) fixed binary;
do i = lbound(z,1) to hbound(z,1);
maxv = max(z(i), maxv);
end;
put skip data (maxv); put skip;
return (maxv);
end maxval;
min... |
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
... | #IS-BASIC | IS-BASIC | 100 PROGRAM "CocktSrt.bas"
110 RANDOMIZE
120 NUMERIC ARRAY(5 TO 24)
130 CALL INIT(ARRAY)
140 CALL WRITE(ARRAY)
150 CALL COCKTAILSORT(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... |
http://rosettacode.org/wiki/Solve_a_Hopido_puzzle | Solve a Hopido puzzle | Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Pos... | #11l | 11l | V neighbours = [[2, 2], [-2, 2], [2, -2], [-2, -2], [3, 0], [0, 3], [-3, 0], [0, -3]]
V cnt = 0
V pWid = 0
V pHei = 0
F is_valid(a, b)
R -1 < a & a < :pWid & -1 < b & b < :pHei
F iterate(&pa, x, y, v)
I v > :cnt
R 1
L(i) 0 .< :neighbours.len
V a = x + :neighbours[i][0]
V b = y + :neighb... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.