bubble_sort Subroutine

public pure subroutine bubble_sort(list)

Implementing insertion sort instead of this algorithm is considered.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(inout) :: list(:)

Source Code

   pure subroutine bubble_sort(list)
      !! Implementing insertion sort instead of this algorithm is considered.
      implicit none
      integer(int32), intent(inout) :: list(:)

      integer :: i, j, siz, tmp

      siz = size(list)

      do i = 1, siz-1
         do j = i+1, siz
            if (list(i) > list(j)) then
               tmp = list(i)
               list(i) = list(j)
               list(j) = tmp
            end if
         end do
      end do

   end subroutine bubble_sort