RosettaCodeData/Task/Sort-an-integer-array/NetRexx/sort-an-integer-array-2.net...

73 lines
1.5 KiB
Plaintext

/* NetRexx */
options replace format comments java crossref savelog symbols
/*REXX program to sort an integer array.*/
numeric digits 20 /*handle larger numbers.*/
a = ''
a[ 1]= 1
a[ 2]= 0
a[ 3]= -1
a[ 4]= 0
a[ 5]= 5
a[ 6]= 0
a[ 7]= -61
a[ 8]= 0
a[ 9]= 1385
a[10]= 0
a[11]= -50521
a[12]= 0
a[13]= 2702765
a[14]= 0
a[15]= -199360981
a[16]= 0
a[17]= 19391512145
a[18]= 0
a[19]= -2404879675441
a[20]= 0
a[21]= 370371188237525
size = 21 /*we have a list of 21 Euler numbers.*/
tell('un-sorted', a, size)
a[0] = size
esort(a, 1)
tell(' sorted', a, size)
return
/*----------------------------------ESORT subroutine--------------------*/
method esort(a, size) public static
--esort: procedure expose a.;
h = a[0]
loop while h > 1
h = h % 2
loop i = 1 for a[0] - h
j = i
k = h + i
loop while a[k] < a[j]
t = a[j]
a[j] = a[k]
a[k] = t
if h >= j then leave
j = j - h
k = k - h
end
end i
end
return
/*----------------------------------TELL subroutine---------------------*/
method tell(arg, a, size) public static
--tell:
say arg.center(40, '-')
loop j = 1 for size
say arg 'array element' j.right(size.length)'='a[j].right(25)
end j
say
return