Sorting algorithms/Sleep sort: Difference between revisions

no edit summary
m (→‎{{header|Scala}}: Scala would've printed newlines instead of spaces)
No edit summary
Line 552:
 
sorted 0 1 2 2 4 5 5 5 6 6 9</pre>
 
=={{header|Fortran}}==
<lang Fortran>
program sleepSort
use omp_lib
implicit none
integer::nArgs,myid,i,stat
integer,allocatable::intArg(:)
character(len=5)::arg
 
!$omp master
nArgs=command_argument_count()
if(nArgs==0)stop ' : No argument is given !'
allocate(intArg(nArgs))
do i=1,nArgs
call get_command_argument(i, arg)
read(arg,'(I5)',iostat=stat)intArg(i)
if(intArg(i)<0 .or. stat/=0) stop&
&' :Only 0 or positive integer allowed !'
end do
call omp_set_num_threads(nArgs)
!$omp end master
 
!$omp parallel private(myid)
myid =omp_get_thread_num()
call sleepNprint(intArg(myid+1))
!$omp end parallel
 
contains
subroutine sleepNprint(nSeconds)
integer::nSeconds
call sleep(nSeconds)
print*,nSeconds
end subroutine sleepNprint
end program sleepSort
</lang>
Compile and Output:
<pre>
gortran -fopenmp sleepSort.f90 -o sleepSort
./sleepSort 0 3 1 4 1 5 9
0
1
1
3
4
5
9
</pre>
 
=={{header|Go}}==
Anonymous user