Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -3,6 +3,6 @@
|
|||
int main()
|
||||
{
|
||||
int nums[] = {2,4,3,1,2};
|
||||
std::sort(nums, nums+5);
|
||||
std::sort(nums, nums+sizeof(nums)/sizeof(int));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
a = [5, 2, 4, 1, 6, 7, 9, 3, 8, 0]
|
||||
sort[a]
|
||||
|
|
@ -1,47 +1,37 @@
|
|||
/*REXX program to sort (E-sort) an array (which contains integers). */
|
||||
numeric digits 30 /*handle larger numbers.*/
|
||||
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 /*have a list of 21 Euler numbers*/
|
||||
call tell 'un-sorted'
|
||||
call esort size
|
||||
call tell ' sorted'
|
||||
/*REXX program sorts (E-sort) an arra y (which contains integers). */
|
||||
numeric digits 30 /*handle larger Euler numbers. */
|
||||
@. = 0 /*default for all Euler numbers. */
|
||||
@.1= 1
|
||||
@.3= -1
|
||||
@.5= 5
|
||||
@.7= -61
|
||||
@.9= 1385
|
||||
@.11= -50521
|
||||
@.13= 2702765
|
||||
@.15= -199360981
|
||||
@.17= 19391512145
|
||||
@.19= -2404879675441
|
||||
@.21= 370371188237525
|
||||
size=21 /*indicate there are 21 Euler #'s*/
|
||||
call tell 'un-sorted' /*display the array before sort. */
|
||||
call esort size /*sort the array of Euler numbers*/
|
||||
call tell ' sorted' /*display the array after sort. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────ESORT subroutine────────────────────*/
|
||||
esort: procedure expose a.; parse arg N; h=N
|
||||
do while h>1; h=h%2
|
||||
do i=1 for N-h; j=i; k=h+i
|
||||
do while a.k<a.j
|
||||
parse value a.j a.k with a.k a.j /*swap two elements.*/
|
||||
if h>=j then leave; j=j-h; k=k-h
|
||||
end /*while a.k<a.j*/
|
||||
esort: procedure expose @.; parse arg N; h=N
|
||||
do while h>1; h=h%2
|
||||
do i=1 for N-h; j=i; k=h+i
|
||||
do while @.k<@.j
|
||||
parse value @.j @.k with @.k @.j /*swap two elements.*/
|
||||
if h>=j then leave; j=j-h; k=k-h
|
||||
end /*while @.k<@.j*/
|
||||
end /*i*/
|
||||
end /*while h>1*/
|
||||
return
|
||||
/*──────────────────────────────────TELL subroutine─────────────────────*/
|
||||
tell: say center(arg(1),50,'─')
|
||||
do j=1 for size
|
||||
say arg(1) 'array element' right(j,length(size))'='right(a.j,20)
|
||||
do j=1 for size
|
||||
say arg(1) 'array element' right(j,length(size))'='right(@.j,20)
|
||||
end /*j*/
|
||||
say
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,30 +1,29 @@
|
|||
/*REXX program sorts (using E-sort) a list of some interesting integers.*/
|
||||
|
||||
/*quotes aren't needed if all elements in a list are non-negative.*/
|
||||
/* [↓] quotes aren't needed if all elements in a list are non-negative.*/
|
||||
bell= 1 1 2 5 15 52 203 877 4140 21147 115975 /*some Bell numbers.*/
|
||||
bern= '1 -1 1 0 -1 0 1 0 -1 0 5 0 -691 0 7 0 -3617' /*some Bernoulli num*/
|
||||
perrin=3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 /*some Perrin nums. */
|
||||
list=bell bern perrin /*throw 'em───>a pot*/
|
||||
say 'original =' list /*an annoucement... */
|
||||
perrin= 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 /*some Perrin nums. */
|
||||
list=bell bern perrin /*throw 'em───►a pot*/
|
||||
say 'unsorted =' list /*an announcement···*/
|
||||
size=words(list) /*nice to have SIZE.*/
|
||||
do j=1 for size /*build an array, 1 */
|
||||
a.j=word(list,j) /*element at a time.*/
|
||||
end /*j*/
|
||||
do j=1 for size /*build an array, 1 */
|
||||
@.j=word(list,j) /*element at a time.*/
|
||||
end /*j*/
|
||||
call esort size /*sort the stuff. */
|
||||
bList=a.1 /*start with 1st. */
|
||||
do k=2 to size /*build a list. */
|
||||
bList=bList a.k
|
||||
end /*k*/
|
||||
bList= /*list: null so far.*/
|
||||
do k=1 for size /*build a list. */
|
||||
bList=strip(bList @.k) /*append it to list.*/
|
||||
end /*k*/
|
||||
say ' sorted =' bList /*show & tell time. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────ESORT subroutine────────────────────*/
|
||||
esort: procedure expose a.; parse arg N; h=N
|
||||
do while h>1; h=h%2
|
||||
do i=1 for N-h; j=i; k=h+i
|
||||
do while a.k<a.j
|
||||
parse value a.j a.k with a.k a.j /*swap two elements.*/
|
||||
if h>=j then leave; j=j-h; k=k-h
|
||||
end /*while a.k<a.j*/
|
||||
esort: procedure expose @.; parse arg N; h=N /*get the item count*/
|
||||
do while h>1; h=h%2 /*partition array. */
|
||||
do i=1 for N-h; j=i; k=h+i
|
||||
do while @.k<@.j
|
||||
parse value @.j @.k with @.k @.j /*swap two elements.*/
|
||||
if h>=j then leave; j=j-h; k=k-h
|
||||
end /*while @.k<@.j*/
|
||||
end /*i*/
|
||||
end /*while h>1*/
|
||||
return
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
fn main() {
|
||||
let mut a = vec!(9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
a.sort();
|
||||
println!("{}", a);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import scala.compat.Platform
|
||||
|
||||
object Sort_an_integer_array extends App {
|
||||
val array = Array((for (i <- 0 to 10) yield scala.util.Random.nextInt()):
|
||||
_* /*Sequence is passed as multiple parameters to Array(xs : T*)*/)
|
||||
|
||||
/** Function test the array if it is in order */
|
||||
def isSorted[T](arr: Array[T]) = array.sliding(2).forall(pair => pair(0) <= pair(1))
|
||||
|
||||
assert(!isSorted(array), "Not random")
|
||||
scala.util.Sorting.quickSort(array)
|
||||
assert(isSorted(array), "Not sorted")
|
||||
|
||||
println(s"Array in sorted order.\nSuccessfully completed without errors. [total ${Platform.currentTime - executionStart} ms]")
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
println(List(5,2,78,2,578,-42).sorted)
|
||||
//--> List(-42, 2, 2, 5, 78, 578)
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
println(List(5,2,78,2,578,-42).sortWith(_<_))
|
||||
//--> List(-42, 2, 2, 5, 78, 578)
|
||||
Loading…
Add table
Add a link
Reference in a new issue