program sort implicit none integer,parameter::numitems=10 integer::i,comparisoncount = 0 ! ANALYSIS OF EFFICIENCY OF SELECTIONSORT integer,dimension(numitems)::item open(unit = 1,file = 'unsorted',status = 'old') open(unit = 2,file = 'sorted',status = 'new') do i = 1,numitems read(1,'(bz,i3)')item(i) end do call selectionsort(item) do i = 1,numitems write(2,'(i3)')item(i) end do print*,'There were',comparisoncount,'comparisons' contains subroutine selectionsort(x) implicit none integer,dimension(numitems),intent(inout)::x integer::i,j do i = 1,numitems-1 do j = i+1,numitems if (x(i) > x(j)) call swapint(x(i),x(j)) comparisoncount = comparisoncount + 1 end do end do end subroutine end program subroutine swapint(x,y) implicit none integer,intent(inout)::x,y integer::temporary temporary = x x = y y = temporary end subroutine