program test20
  integer, dimension (10)::a = (/3,4,2,5,0,6,1,9,7,8/)
  integer :: i,n
  n=10
  write(*,*) a
  write(*,*) a
  call selectionsort(a,n,10)
  write(*,*) a
end program test20

subroutine switch(first,second)
  integer temp,first,second
  temp = first
  first = second
  second = temp
end subroutine switch

subroutine selectionsort (a,n, last)
  integer a(n), n, last
  integer first,j,minindex
  do first=1,last-1
     minindex = first
     do j = first+1,last
        if (a(j) < a(minindex)) then
           minindex = j
        end if
     end do
     call switch (a(first),a(minindex))
  end do
end subroutine selectionsort




