WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sort three variables

C: #include<string.h>
#include<stdlib.h>
#include<stdio.h>

#define MAX 3

int main()
{
  char values[MAX][100],tempStr[100];
  int i,j,isString=0;
  double val[MAX],temp;
  
  for(i=0;i<MAX;i++){
    printf("Enter %d%s value : ",i+1,(i==0)?"st":((i==1)?"nd":"rd"));
    fgets(values[i],100,stdin);
    
    for(j=0;values[i][j]!=00;j++){
      if(((values[i][j]<'0' || values[i][j]>'9') && (values[i][j]!='.' ||values[i][j]!='-'||values[i][j]!='+'))
      ||((values[i][j]=='.' ||values[i][j]=='-'||values[i][j]=='+')&&(values[i][j+1]<'0' || values[i][j+1]>'9')))
        isString = 1;
    }
  }
  
  if(isString==0){
    for(i=0;i<MAX;i++)
      val[i] = atof(values[i]);
  }
  
  for(i=0;i<MAX-1;i++){
    for(j=i+1;j<MAX;j++){
      if(isString==0 && val[i]>val[j]){
        temp = val[j];
        val[j] = val[i];
        val[i] = temp;
      }
        
      else if(values[i][0]>values[j][0]){
        strcpy(tempStr,values[j]);
        strcpy(values[j],values[i]);
        strcpy(values[i],tempStr);
      }
    }
  }
  
  for(i=0;i<MAX;i++)
    isString==1?printf("%c = %s",'X'+i,values[i]):printf("%c = %lf",'X'+i,val[i]);
  
  return 0;
}









COBOL:        program-id. 3var.
       data division.
       working-storage section.
       1 n binary pic 9(4).
       1 num pic -(7)9.
       1 a1 pic x(32) value "lions, tigers, and".
       1 a2 pic x(32) value "bears, oh my!".
       1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
       1 n1 pic x(8) value "77444".
       1 n2 pic x(8) value "-12".
       1 n3 pic x(8) value "0".
       1 alpha-table.
        2 alpha-entry occurs 3 pic x(32).
       1 numeric-table.
        2 numeric-entry occurs 3 pic s9(8).
       1 filler value "x = y = z = ".
        2 lead-in occurs 3 pic x(4).
       procedure division.
       begin.
           move a1 to alpha-entry (1)
           move a2 to alpha-entry (2)
           move a3 to alpha-entry (3)
           sort alpha-entry ascending alpha-entry
           perform varying n from 1 by 1
           until n > 3
               display lead-in (n) alpha-entry (n)
           end-perform

           display space

           compute numeric-entry (1) = function numval (n1)
           compute numeric-entry (2) = function numval (n2)
           compute numeric-entry (3) = function numval (n3)
           sort numeric-entry ascending numeric-entry
           perform varying n from 1 by 1
           until n > 3
               move numeric-entry (n) to num
               display lead-in (n) num
           end-perform

           stop run
           .
       end program 3var.
Task: Sort three variables



C#: using System;
public class Program
{
    public static void Main()
    {
        (int x, int y, int z) = (77444, -12, 0);

        
        if (x > y) (x, y) = (y, x);
        if (x > z) (x, z) = (z, x);
        if (y > z) (y, z) = (z, y);
        Console.WriteLine((x, y, z));

        var (a, b, c) = (
            "lions, tigers, and",
            "bears, oh my!",
            "(from the 'Wizard of OZ')");
        
        
        Sort(ref a, ref b, ref c);
        Console.WriteLine((a, b, c));
    }
    
    public static void Sort<T>(ref T a, ref T b, ref T c)
        where T : IComparable<T>
    {
        if (a.CompareTo(b) > 0) (a, b) = (b, a);
        if (a.CompareTo(c) > 0) (a, c) = (c, a);
        if (b.CompareTo(c) > 0) (b, c) = (c, b);
    }
}







COBOL:        program-id. 3var.
       data division.
       working-storage section.
       1 n binary pic 9(4).
       1 num pic -(7)9.
       1 a1 pic x(32) value "lions, tigers, and".
       1 a2 pic x(32) value "bears, oh my!".
       1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
       1 n1 pic x(8) value "77444".
       1 n2 pic x(8) value "-12".
       1 n3 pic x(8) value "0".
       1 alpha-table.
        2 alpha-entry occurs 3 pic x(32).
       1 numeric-table.
        2 numeric-entry occurs 3 pic s9(8).
       1 filler value "x = y = z = ".
        2 lead-in occurs 3 pic x(4).
       procedure division.
       begin.
           move a1 to alpha-entry (1)
           move a2 to alpha-entry (2)
           move a3 to alpha-entry (3)
           sort alpha-entry ascending alpha-entry
           perform varying n from 1 by 1
           until n > 3
               display lead-in (n) alpha-entry (n)
           end-perform

           display space

           compute numeric-entry (1) = function numval (n1)
           compute numeric-entry (2) = function numval (n2)
           compute numeric-entry (3) = function numval (n3)
           sort numeric-entry ascending numeric-entry
           perform varying n from 1 by 1
           until n > 3
               move numeric-entry (n) to num
               display lead-in (n) num
           end-perform

           stop run
           .
       end program 3var.
Task: Sort three variables


C++: #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
 
template < class T >
void sort3( T& x, T& y, T& z) {
    std::vector<T> v{x, y, z};
    std::sort(v.begin(), v.end());
    x = v[0]; y = v[1]; z = v[2];
}
int main() {
    int xi = 77444, yi = -12, zi = 0;
    sort3( xi, yi, zi );
    std::cout << xi << "\n" << yi << "\n" << zi << "\n\n";
 
    std::string xs, ys, zs;
    xs = "lions, tigers, and";
    ys = "bears, oh my!";
    zs = "(from the \"Wizard of OZ\")";
    sort3( xs, ys, zs );
    std::cout << xs << "\n" << ys << "\n" << zs << "\n\n";
 
    float xf = 11.3f, yf = -9.7f, zf = 11.17f;
    sort3( xf, yf, zf );
    std::cout << xf << "\n" << yf << "\n" << zf << "\n\n";
}








COBOL:        program-id. 3var.
       data division.
       working-storage section.
       1 n binary pic 9(4).
       1 num pic -(7)9.
       1 a1 pic x(32) value "lions, tigers, and".
       1 a2 pic x(32) value "bears, oh my!".
       1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
       1 n1 pic x(8) value "77444".
       1 n2 pic x(8) value "-12".
       1 n3 pic x(8) value "0".
       1 alpha-table.
        2 alpha-entry occurs 3 pic x(32).
       1 numeric-table.
        2 numeric-entry occurs 3 pic s9(8).
       1 filler value "x = y = z = ".
        2 lead-in occurs 3 pic x(4).
       procedure division.
       begin.
           move a1 to alpha-entry (1)
           move a2 to alpha-entry (2)
           move a3 to alpha-entry (3)
           sort alpha-entry ascending alpha-entry
           perform varying n from 1 by 1
           until n > 3
               display lead-in (n) alpha-entry (n)
           end-perform

           display space

           compute numeric-entry (1) = function numval (n1)
           compute numeric-entry (2) = function numval (n2)
           compute numeric-entry (3) = function numval (n3)
           sort numeric-entry ascending numeric-entry
           perform varying n from 1 by 1
           until n > 3
               move numeric-entry (n) to num
               display lead-in (n) num
           end-perform

           stop run
           .
       end program 3var.
Task: Sort three variables





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;
        int[] sortedInt = Stream.of(iA, iB, iC).sorted().mapToInt(Integer::intValue).toArray();
        iA = sortedInt[0];
        iB = sortedInt[1];
        iC = sortedInt[2];
        System.out.printf("Sorted values: %d %d %d%n", iA, iB, iC);

        String sA = "s21";
        String sB = "s11";
        String sC = "s82";
        Object[] sortedStr = Stream.of(sA, sB, sC).sorted().toArray();
        sA = (String) sortedStr[0];
        sB = (String) sortedStr[1];
        sC = (String) sortedStr[2];
        System.out.printf("Sorted values: %s %s %s%n", sA, sB, sC);

        Box bA = new Box(200);
        Box bB = new Box(12);
        Box bC = new Box(143);
        
        Object[] sortedBox = Stream.of(bA, bB, bC).sorted(Comparator.comparingInt(a -> a.weightKg)).toArray();
        bA = (Box) sortedBox[0];
        bB = (Box) sortedBox[1];
        bC = (Box) sortedBox[2];
        System.out.printf("Sorted Boxes: %dKg %dKg %dKg%n", bA.weightKg, bB.weightKg, bC.weightKg);
    }
}





COBOL:        program-id. 3var.
       data division.
       working-storage section.
       1 n binary pic 9(4).
       1 num pic -(7)9.
       1 a1 pic x(32) value "lions, tigers, and".
       1 a2 pic x(32) value "bears, oh my!".
       1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
       1 n1 pic x(8) value "77444".
       1 n2 pic x(8) value "-12".
       1 n3 pic x(8) value "0".
       1 alpha-table.
        2 alpha-entry occurs 3 pic x(32).
       1 numeric-table.
        2 numeric-entry occurs 3 pic s9(8).
       1 filler value "x = y = z = ".
        2 lead-in occurs 3 pic x(4).
       procedure division.
       begin.
           move a1 to alpha-entry (1)
           move a2 to alpha-entry (2)
           move a3 to alpha-entry (3)
           sort alpha-entry ascending alpha-entry
           perform varying n from 1 by 1
           until n > 3
               display lead-in (n) alpha-entry (n)
           end-perform

           display space

           compute numeric-entry (1) = function numval (n1)
           compute numeric-entry (2) = function numval (n2)
           compute numeric-entry (3) = function numval (n3)
           sort numeric-entry ascending numeric-entry
           perform varying n from 1 by 1
           until n > 3
               move numeric-entry (n) to num
               display lead-in (n) num
           end-perform

           stop run
           .
       end program 3var.
Task: Sort three variables







Python: 
a= raw_input("Enter values one by one ..\n1.").strip()
b=raw_input("2.").strip()
c=raw_input("3.").strip()
if a>b :
   a,b = b,a 
if a>c:
   a,c = c,a 
if b>c:
   b,c = c,b 
print(str(a)+" "+str(b)+" "+str(c))



COBOL:        program-id. 3var.
       data division.
       working-storage section.
       1 n binary pic 9(4).
       1 num pic -(7)9.
       1 a1 pic x(32) value "lions, tigers, and".
       1 a2 pic x(32) value "bears, oh my!".
       1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
       1 n1 pic x(8) value "77444".
       1 n2 pic x(8) value "-12".
       1 n3 pic x(8) value "0".
       1 alpha-table.
        2 alpha-entry occurs 3 pic x(32).
       1 numeric-table.
        2 numeric-entry occurs 3 pic s9(8).
       1 filler value "x = y = z = ".
        2 lead-in occurs 3 pic x(4).
       procedure division.
       begin.
           move a1 to alpha-entry (1)
           move a2 to alpha-entry (2)
           move a3 to alpha-entry (3)
           sort alpha-entry ascending alpha-entry
           perform varying n from 1 by 1
           until n > 3
               display lead-in (n) alpha-entry (n)
           end-perform

           display space

           compute numeric-entry (1) = function numval (n1)
           compute numeric-entry (2) = function numval (n2)
           compute numeric-entry (3) = function numval (n3)
           sort numeric-entry ascending numeric-entry
           perform varying n from 1 by 1
           until n > 3
               move numeric-entry (n) to num
               display lead-in (n) num
           end-perform

           stop run
           .
       end program 3var.
Task: Sort three variables








VB: Module Module1

    Sub Swap(Of T)(ByRef a As T, ByRef b As T)
        Dim c = a
        a = b
        b = c
    End Sub

    Sub Sort(Of T As IComparable(Of T))(ByRef a As T, ByRef b As T, ByRef c As T)
        If a.CompareTo(b) > 0 Then
            Swap(a, b)
        End If
        If a.CompareTo(c) > 0 Then
            Swap(a, c)
        End If
        If b.CompareTo(c) > 0 Then
            Swap(b, c)
        End If
    End Sub

    Sub Main()
        Dim x = 77444
        Dim y = -12
        Dim z = 0
        Sort(x, y, z)
        Console.WriteLine((x, y, z))

        Dim a = "lions, tigers, and"
        Dim b = "bears, oh my!"
        Dim c = "(from the 
        Sort(a, b, c)
        Console.WriteLine((a, b, c))
    End Sub

End Module


COBOL:        program-id. 3var.
       data division.
       working-storage section.
       1 n binary pic 9(4).
       1 num pic -(7)9.
       1 a1 pic x(32) value "lions, tigers, and".
       1 a2 pic x(32) value "bears, oh my!".
       1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
       1 n1 pic x(8) value "77444".
       1 n2 pic x(8) value "-12".
       1 n3 pic x(8) value "0".
       1 alpha-table.
        2 alpha-entry occurs 3 pic x(32).
       1 numeric-table.
        2 numeric-entry occurs 3 pic s9(8).
       1 filler value "x = y = z = ".
        2 lead-in occurs 3 pic x(4).
       procedure division.
       begin.
           move a1 to alpha-entry (1)
           move a2 to alpha-entry (2)
           move a3 to alpha-entry (3)
           sort alpha-entry ascending alpha-entry
           perform varying n from 1 by 1
           until n > 3
               display lead-in (n) alpha-entry (n)
           end-perform

           display space

           compute numeric-entry (1) = function numval (n1)
           compute numeric-entry (2) = function numval (n2)
           compute numeric-entry (3) = function numval (n3)
           sort numeric-entry ascending numeric-entry
           perform varying n from 1 by 1
           until n > 3
               move numeric-entry (n) to num
               display lead-in (n) num
           end-perform

           stop run
           .
       end program 3var.
Task: Sort three variables






PHP: <?php

$x = 'lions, tigers, and';
$y = 'bears, oh my!';
$z = '(from the "Wizard of OZ")';
$items = [$x, $y, $z];
sort($items);

list($x, $y, $z) = $items;

echo <<<EOT
Case 1:
  x = $x
  y = $y
  z = $z

EOT;

$x = 77444;
$y = -12;
$z = 0;
$items = [$x, $y, $z];
sort($items);

list($x, $y, $z) = $items;

echo <<<EOT
Case 2:
  x = $x
  y = $y
  z = $z

EOT;
Task: Sort three variables






PHP: <?php

$x = 'lions, tigers, and';
$y = 'bears, oh my!';
$z = '(from the "Wizard of OZ")';
$items = [$x, $y, $z];
sort($items);

list($x, $y, $z) = $items;

echo <<<EOT
Case 1:
  x = $x
  y = $y
  z = $z

EOT;

$x = 77444;
$y = -12;
$z = 0;
$items = [$x, $y, $z];
sort($items);

list($x, $y, $z) = $items;

echo <<<EOT
Case 2:
  x = $x
  y = $y
  z = $z

EOT;






Ada: with Ada.Text_IO;
with Ada.Strings.Unbounded;

procedure Sort_Three is

   generic
      type Element_Type is private;
      with function "<" (Left, Right : in Element_Type) return Boolean;
   procedure Generic_Sort (X, Y, Z : in out Element_Type);

   procedure Generic_Sort (X, Y, Z : in out Element_Type)
   is
      procedure Swap (Left, Right : in out Element_Type) is
         T : constant Element_Type := Left;
      begin
         Left := Right;
         Right := T;
      end Swap;
   begin
      if Y < X then Swap (X, Y); end if;
      if Z < Y then Swap (Y, Z); end if;
      if Y < X then Swap (X, Y); end if;
   end Generic_Sort;

   procedure Test_Unbounded_Sort is
      use Ada.Text_IO;
      use Ada.Strings.Unbounded;

      X : Unbounded_String := To_Unbounded_String ("lions, tigers, and");
      Y : Unbounded_String := To_Unbounded_String ("bears, oh my!");
      Z : Unbounded_String := To_Unbounded_String ("(from the ""Wizard of OZ"")");

      procedure Sort is
         new Generic_Sort (Unbounded_String, "<");
   begin
      Sort (X, Y, Z);
      Put_Line (To_String (X));
      Put_Line (To_String (Y));
      Put_Line (To_String (Z));
      New_Line;
   End Test_Unbounded_Sort;

   procedure Test_Integer_Sort is

      use Ada.Text_IO;

      procedure Sort is
         new Generic_Sort (Integer, "<");

      X : Integer := 77444;
      Y : Integer :=   -12;
      Z : Integer :=     0;
   begin
      Sort (X, Y, Z);
      Put_Line (X'Image);
      Put_Line (Y'Image);
      Put_Line (Z'Image);
      New_Line;
   end Test_Integer_Sort;

begin
   Test_Unbounded_Sort;
   Test_Integer_Sort;
end Sort_Three;
Task: Sort three variables






PHP: <?php

$x = 'lions, tigers, and';
$y = 'bears, oh my!';
$z = '(from the "Wizard of OZ")';
$items = [$x, $y, $z];
sort($items);

list($x, $y, $z) = $items;

echo <<<EOT
Case 1:
  x = $x
  y = $y
  z = $z

EOT;

$x = 77444;
$y = -12;
$z = 0;
$items = [$x, $y, $z];
sort($items);

list($x, $y, $z) = $items;

echo <<<EOT
Case 2:
  x = $x
  y = $y
  z = $z

EOT;




COBOL:        program-id. 3var.
       data division.
       working-storage section.
       1 n binary pic 9(4).
       1 num pic -(7)9.
       1 a1 pic x(32) value "lions, tigers, and".
       1 a2 pic x(32) value "bears, oh my!".
       1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
       1 n1 pic x(8) value "77444".
       1 n2 pic x(8) value "-12".
       1 n3 pic x(8) value "0".
       1 alpha-table.
        2 alpha-entry occurs 3 pic x(32).
       1 numeric-table.
        2 numeric-entry occurs 3 pic s9(8).
       1 filler value "x = y = z = ".
        2 lead-in occurs 3 pic x(4).
       procedure division.
       begin.
           move a1 to alpha-entry (1)
           move a2 to alpha-entry (2)
           move a3 to alpha-entry (3)
           sort alpha-entry ascending alpha-entry
           perform varying n from 1 by 1
           until n > 3
               display lead-in (n) alpha-entry (n)
           end-perform

           display space

           compute numeric-entry (1) = function numval (n1)
           compute numeric-entry (2) = function numval (n2)
           compute numeric-entry (3) = function numval (n3)
           sort numeric-entry ascending numeric-entry
           perform varying n from 1 by 1
           until n > 3
               move numeric-entry (n) to num
               display lead-in (n) num
           end-perform

           stop run
           .
       end program 3var.
Task: Sorting algorithms_Radix sort

C: #include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>


#define ARR_LEN(ARR) (sizeof ARR / sizeof *ARR)

#define RAND_RNG(M,N) (M + rand() / (RAND_MAX / (N - M + 1) + 1));

static void swap(unsigned *a, unsigned *b) {
    unsigned tmp = *a;
    *a = *b;
    *b = tmp;
}


static void rad_sort_u(unsigned *from, unsigned *to, unsigned bit)
{
	if (!bit || to < from + 1) return;

	unsigned *ll = from, *rr = to - 1;
	for (;;) {
		
		while (ll < rr && !(*ll & bit)) ll++;
		while (ll < rr &&  (*rr & bit)) rr--;
		if (ll >= rr) break;
		swap(ll, rr);
	}

	if (!(bit & *ll) && ll < to) ll++;
	bit >>= 1;

	rad_sort_u(from, ll, bit);
	rad_sort_u(ll, to, bit);
}


static void radix_sort(int *a, const size_t len)
{
	size_t i;
	unsigned *x = (unsigned*) a;

	for (i = 0; i < len; i++) 
            x[i] ^= INT_MIN;

        rad_sort_u(x, x + len, INT_MIN);

        for (i = 0; i < len; i++) 
            x[i] ^= INT_MIN;
}

int main(void)
{
        
    srand(time(NULL));
    int x[16];

     for (size_t i = 0; i < ARR_LEN(x); i++) 
        x[i] = RAND_RNG(-128,127)

    radix_sort(x, ARR_LEN(x));

    for (size_t i = 0; i < ARR_LEN(x); i++) 
        printf("%d%c", x[i], i + 1 < ARR_LEN(x) ? ' ' : '\n');
}
Task: Sorting algorithms_Radix sort



C#: using System;

namespace RadixSort
{
    class Program
    {
        static void Sort(int[] old)
        {
            int i, j;
            int[] tmp = new int[old.Length];
            for (int shift = 31; shift > -1; --shift)
            {
                j = 0;
                for (i = 0; i < old.Length; ++i)
                {
                    bool move = (old[i] << shift) >= 0;
                    if (shift == 0 ? !move : move)  
                        old[i-j] = old[i];
                    else                            
                        tmp[j++] = old[i];
                }
                Array.Copy(tmp, 0, old, old.Length-j, j);
            }
        }
        static void Main(string[] args)
        {
            int[] old = new int[] { 2, 5, 1, -3, 4 };
            Console.WriteLine(string.Join(", ", old));
            Sort(old);
            Console.WriteLine(string.Join(", ", old));
            Console.Read();
        }
    }
}
Task: Sorting algorithms_Radix sort


C++: #include <algorithm>
#include <iostream>
#include <iterator>


class radix_test
{
    const int bit; 
public:
    radix_test(int offset) : bit(offset) {} 

    bool operator()(int value) const 
    {
        if (bit == 31) 
            return value < 0; 
        else
            return !(value & (1 << bit)); 
    }
};


void lsd_radix_sort(int *first, int *last)
{
    for (int lsb = 0; lsb < 32; ++lsb) 
    {
        std::stable_partition(first, last, radix_test(lsb));
    }
}


void msd_radix_sort(int *first, int *last, int msb = 31)
{
    if (first != last && msb >= 0)
    {
        int *mid = std::partition(first, last, radix_test(msb));
        msb--; 
        msd_radix_sort(first, mid, msb); 
        msd_radix_sort(mid, last, msb); 
    }
}


int main()
{
    int data[] = { 170, 45, 75, -90, -802, 24, 2, 66 };

    lsd_radix_sort(data, data + 8);
    

    std::copy(data, data + 8, std::ostream_iterator<int>(std::cout, " "));

    return 0;
}
Task: Sorting algorithms_Radix sort





Java: public static int[] sort(int[] old) {
    
    for (int shift = Integer.SIZE - 1; shift > -1; shift--) {
        
        int[] tmp = new int[old.length];
        
        int j = 0;

        
        for (int i = 0; i < old.length; i++) {
            
            boolean move = old[i] << shift >= 0;

            
            if (shift == 0 ? !move : move) {
                tmp[j] = old[i];
                j++;
            } else {
                
                old[i - j] = old[i];
            }
        }

        
        for (int i = j; i < tmp.length; i++) {
            tmp[i] = old[i - j];
        }

        
        old = tmp;
    }

    return old;
}
Task: Sorting algorithms_Radix sort







Python: 
from math import log
 
def getDigit(num, base, digit_num):
    
    return (num // base ** digit_num) % base  
 
def makeBlanks(size):
    
    return [ [] for i in range(size) ]  
 
def split(a_list, base, digit_num):
    buckets = makeBlanks(base)
    for num in a_list:
        
        buckets[getDigit(num, base, digit_num)].append(num)  
    return buckets
 

def merge(a_list):
    new_list = []
    for sublist in a_list:
       new_list.extend(sublist)
    return new_list
 
def maxAbs(a_list):
    
    return max(abs(num) for num in a_list)

def split_by_sign(a_list):
    
    
    buckets = [[], []]
    for num in a_list:
        if num < 0:
            buckets[0].append(num)
        else:
            buckets[1].append(num)
    return buckets
 
def radixSort(a_list, base):
    
    passes = int(round(log(maxAbs(a_list), base)) + 1) 
    new_list = list(a_list)
    for digit_num in range(passes):
        new_list = merge(split(new_list, base, digit_num))
    return merge(split_by_sign(new_list))
Task: Sorting algorithms_Radix sort




Go: package main

import (
    "bytes"
    "encoding/binary"
    "fmt"
)


type word int32
const wordLen = 4
const highBit = -1 << 31

var data = []word{170, 45, 75, -90, -802, 24, 2, 66}

func main() {
    buf := bytes.NewBuffer(nil)
    ds := make([][]byte, len(data))
    for i, x := range data {
        binary.Write(buf, binary.LittleEndian, x^highBit)
        b := make([]byte, wordLen)
        buf.Read(b)
        ds[i] = b
    }
    bins := make([][][]byte, 256)
    for i := 0; i < wordLen; i++ {
        for _, b := range ds {
            bins[b[i]] = append(bins[b[i]], b)
        }
        j := 0
        for k, bs := range bins {
            copy(ds[j:], bs)
            j += len(bs)
            bins[k] = bs[:0]
        }
    }
    fmt.Println("original:", data)
    var w word
    for i, b := range ds {
        buf.Write(b)
        binary.Read(buf, binary.LittleEndian, &w)
        data[i] = w^highBit
    }
    fmt.Println("sorted:  ", data)
}