b'\n_START_ARTICLE_\nRadix sort\n_START_SECTION_\nC\xc3\xb3digo em MATLAB\n_START_PARAGRAPH_\nfunction  vetor = radixsort(vetor, tamanho)%_NEWLINE_% Ordena vetor de inteiros, exemplo:_NEWLINE_%tamanho = 10000;_NEWLINE_%vetor = floor(10000*rand(tamanho,1));_NEWLINE_%vetor = radixsort(vetor, tamanho);_NEWLINE_%_NEWLINE_ep = 1;_NEWLINE_maior = max(vetor);_NEWLINE__NEWLINE_while floor(maior/ep) > 0_NEWLINE_V = sortrows([mod(floor(vetor/ep), 10), (1:tamanho)\']);_NEWLINE_vetor = vetor(V(:,2));_NEWLINE_ep = ep*10;_NEWLINE_endend\n_START_SECTION_\nC\xc3\xb3digo em C\n_START_PARAGRAPH_\nvoid radixsort(int vetor[], int tamanho) {_NEWLINE_    int i;_NEWLINE_    int *b;_NEWLINE_    int maior = vetor[0];_NEWLINE_    int exp = 1;_NEWLINE__NEWLINE_    b = (int *)calloc(tamanho, sizeof(int));_NEWLINE__NEWLINE_    for (i = 0; i < tamanho; i++) {_NEWLINE_        if (vetor[i] > maior)_NEWLINE_        maior = vetor[i];_NEWLINE_    }_NEWLINE__NEWLINE_    while (maior/exp > 0) {_NEWLINE_        int bucket[10] = { 0 };_NEWLINE_    for (i = 0; i < tamanho; i++)_NEWLINE_        bucket[(vetor[i] / exp) % 10]++;_NEWLINE_    for (i = 1; i < 10; i++)_NEWLINE_        bucket[i] += bucket[i - 1];_NEWLINE_    for (i = tamanho - 1; i >= 0; i--)_NEWLINE_        b[--bucket[(vetor[i] / exp) % 10]] = vetor[i];_NEWLINE_    for (i = 0; i < tamanho; i++)_NEWLINE_        vetor[i] = b[i];_NEWLINE_    exp *= 10;_NEWLINE_    }_NEWLINE__NEWLINE_    free(b);}\n_START_SECTION_\nC\xc3\xb3digo em C#\n_START_PARAGRAPH_\n1 static void RadixSort(int[] vetor) { 2 int i; 3 int[] b; 4 int maior = vetor[0]; 5 int exp = 1; 6  7 b = new int[vetor.Length]; 8  9 for (i = 0; i < vetor.Length; i++) {10 if (vetor[i] > maior)11 maior = vetor[i];12 }13 14 while (maior/exp > 0) {15 int[] bucket = new int[10];16 for (i = 0; i < vetor.Length; i++)17 bucket[(vetor[i] / exp) % 10]++;18 for (i = 1; i < 10; i++)19 bucket[i] += bucket[i - 1];20 for (i = vetor.Length - 1; i >= 0; i--)21 b[--bucket[(vetor[i] / exp) % 10]] = vetor[i];22 for (i = 0; i < vetor.Length; i++)23 vetor[i] = b[i];24 exp *= 10;25 }26 }\n_START_SECTION_\nC\xc3\xb3digo em Java [1]\n_START_PARAGRAPH_\nimport java.util.*;public class TestRadix {_NEWLINE_    private static final int MAX_CHARS = 28;_NEWLINE__NEWLINE_    private static void radixSort(String[] v) {_NEWLINE_Queue<String> queues[] = createQueues();_NEWLINE_for (int pos = maxSize(v) - 1; pos >= 0; pos--) {_NEWLINE_for (int i = 0; i < v.length; i++) {_NEWLINE_int q = queueNo(v[i], pos);_NEWLINE_queues[q].add(v[i]);_NEWLINE_}_NEWLINE_restore(queues, v);_NEWLINE_}_NEWLINE_}_NEWLINE__NEWLINE_private static void restore(Queue<String>[] qs, String[] v) {_NEWLINE_int contv = 0;_NEWLINE_for (int q = 0; q < qs.length; q++)_NEWLINE_while (qs[q].size() > 0)_NEWLINE_v[contv++] = qs[q].remove();_NEWLINE_}_NEWLINE__NEWLINE_private static Queue<String>[] createQueues() {_NEWLINE_LinkedList<String>[] result = new LinkedList[MAX_CHARS];_NEWLINE_for (int i = 0; i < MAX_CHARS; i++) {_NEWLINE_result[i] = new LinkedList<String>();_NEWLINE_}_NEWLINE_return result;_NEWLINE_}_NEWLINE__NEWLINE_private static int queueNo(String string, int pos) {_NEWLINE_if (pos >= string.length()) {_NEWLINE_return 0;_NEWLINE_}_NEWLINE_char ch = string.charAt(pos);_NEWLINE_if ((ch >= \'A\') && (ch <= \'Z\')) {_NEWLINE_return (ch - \'A\' + 1);_NEWLINE_}_NEWLINE_else if (ch >= \'a\' && ch <= \'z\') {_NEWLINE_return ch - \'a\' + 1;_NEWLINE_}_NEWLINE_else {_NEWLINE_return 27;_NEWLINE_}_NEWLINE_}_NEWLINE__NEWLINE_private static int maxSize(String[] v) {_NEWLINE_int maxValue = v[0].length();_NEWLINE__NEWLINE_for (int i = 1; i < v.length; i++) {_NEWLINE_if (maxValue < v[i].length()) {_NEWLINE_maxValue = v[i].length();_NEWLINE_}_NEWLINE_}_NEWLINE_return maxValue;_NEWLINE_}_NEWLINE__NEWLINE_public static void printStringArray(String[] arrToPrint) {_NEWLINE_for (int i = 0; i < arrToPrint.length; i++) {_NEWLINE_System.out.print(arrToPrint[i]+" ");_NEWLINE_}_NEWLINE_System.out.println();_NEWLINE_}_NEWLINE__NEWLINE_/** * @param args Array of strings (set of words) to be sorted (ordered) - Must be passed as parameters */_NEWLINE_public static void main(String[] args) {_NEWLINE_System.out.print("Input: ");_NEWLINE_printStringArray(args);_NEWLINE_radixSort(args);_NEWLINE_System.out.print("\\nOutput: ");_NEWLINE_printStringArray(args);_NEWLINE_}}\n_START_SECTION_\nC\xc3\xb3digo em Java [2]\n_START_PARAGRAPH_\npublic void radixSort(int vector[]){_NEWLINE_for(int digit = 0; digit < 3; digit ++){_NEWLINE_int power = (int) Math.pow(10, digit+1);_NEWLINE__NEWLINE_int z[][] = new int[vector.length][10];_NEWLINE_int n[] = new int[10];_NEWLINE__NEWLINE_for(int i = 0; i < vector.length; i ++){_NEWLINE_int num = vector[i];_NEWLINE_z[n[(num%power)/(power/10)]][(num%power)/(power/10)] = num;_NEWLINE_n[(num%power)/(power/10)]++;_NEWLINE__NEWLINE_}_NEWLINE_int c = 0;_NEWLINE_for(int i = 0; i < 10; i ++){_NEWLINE__NEWLINE_for(int j = 0; j < vector.length; j ++){_NEWLINE_if(j < n[i]){_NEWLINE_vector[c] = z[j][i];_NEWLINE_c++;_NEWLINE_}else{break;}_NEWLINE_}_NEWLINE_}_NEWLINE__NEWLINE_}_NEWLINE_}\n_START_SECTION_\nC\xc3\xb3digo em Python\n_START_PARAGRAPH_\nMAX_CHARS = 28def radix_sort(lista):_NEWLINE_        tamanho_maximo = max([len(palavra) for palavra in lista])_NEWLINE__NEWLINE_        for pos in range(tamanho_maximo*1, 1, -1):_NEWLINE_                baldes = [list() for y in range(MAX_CHARS)]_NEWLINE_                for palavra in lista:_NEWLINE_                        balde = numero_do_balde(palavra, pos)_NEWLINE_                        baldes[balde] += [palavra]_NEWLINE_                lista = sum(baldes, [])_NEWLINE__NEWLINE_        return listadef numero_do_balde(palavra, pos):_NEWLINE_        if (pos >= len(palavra)): return 0_NEWLINE_        ch = palavra[pos]_NEWLINE_        if (ch >= \'A\' and ch <= \'Z\'): return ord(ch) - ord(\'A\') + 1_NEWLINE_        if (ch >= \'a\' and ch <= \'z\'): return ord(ch) - ord(\'a\') + 1_NEWLINE_        return MAX_CHARS-1\n_START_SECTION_\nC\xc3\xb3digo em PHP\n_START_PARAGRAPH_\nfunction radix_sort (&$a, $n){_NEWLINE_    $r = 8;_NEWLINE_    $R = 256;_NEWLINE_    $p = 4;_NEWLINE_    $count = null;_NEWLINE__NEWLINE_    for ($i = 0; $i < $p; ++$i)_NEWLINE_    {_NEWLINE_        for ($j = 0; $j < $R; ++$j)_NEWLINE_            $count[$j] = 0;_NEWLINE_        for ($k = 0; $k < $n; ++$k)_NEWLINE_        {_NEWLINE_            $pos = ($a[$k] >> (r * $i)) & ($R - 1);_NEWLINE_            $count[pos] += 1;_NEWLINE_            $tempArray[$k] = $a[$k];_NEWLINE_        }_NEWLINE_        $pos = 0;_NEWLINE_        for ($j = 0; $j < $R; ++$j)_NEWLINE_        {_NEWLINE_            $tmp = $pos;_NEWLINE_            $pos += $count[$j];_NEWLINE_            $count[$j] = $tmp;_NEWLINE_        }_NEWLINE_        for ($k = 0; $k < $n; ++$k)_NEWLINE_        {_NEWLINE_            $pos = (tempArray[$k] >> ($r * $j)) & ($R - 2);_NEWLINE_            $a[$count[$pos]] = $tempArray[$k];_NEWLINE_            $count[$pos] += 1;_NEWLINE_        }_NEWLINE_    }}'