From c7be463e788c387d90d2bc640f295c3e492dfe4b Mon Sep 17 00:00:00 2001 From: rajdeeptechky <55846486+RajdeepDey010@users.noreply.github.com> Date: Wed, 19 Oct 2022 15:54:15 +0530 Subject: [PATCH] Create BubbleSort.f90 --- Bubble Sort/BubbleSort.f90 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Bubble Sort/BubbleSort.f90 diff --git a/Bubble Sort/BubbleSort.f90 b/Bubble Sort/BubbleSort.f90 new file mode 100644 index 0000000..ad8fbb7 --- /dev/null +++ b/Bubble Sort/BubbleSort.f90 @@ -0,0 +1,26 @@ +module sorting + +contains + +subroutine bubblesort(td,A,n) + integer, intent(in) :: td + integer, intent(in out), dimension(td) :: A + integer, intent(in) :: n + integer :: i, j, temp + logical :: swapped + + do j = n-1, 1, -1 + swapped = .false. + do i = 1, j + if (A(i) > A(i+1)) then + temp = A(i) + A(i) = A(i+1) + A(i+1) = temp + swapped = .true. + end if + end do + if (.not. swapped) exit + end do +end subroutine bubblesort + +end module sorting