Skip to content

Commit 5a42630

Browse files
depateleios
authored andcommitted
Bubblesort Fortran 90 (#390)
* Delete monte_carlo_pi.f90 * init * further implementation * next * finished implementation and docs * Line spacing added * Fixed an error in the .md
1 parent c152208 commit 5a42630

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

contents/bubble_sort/bubble_sort.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
4848
[import:3-28, lang:"lisp"](code/lisp/bubble_sort.lisp)
4949
{% sample lang="nim" %}
5050
[import:5-9, lang:"nim"](code/nim/bubble_sort.nim)
51+
{% sample lang="f90" %}
52+
[import:19-40, lang:"fortran"](code/fortran/bubble.f90)
5153
{% endmethod %}
5254

5355
... And that's it for the simplest bubble sort method.
@@ -101,6 +103,8 @@ Trust me, there are plenty of more complicated algorithms that do precisely the
101103
[import, lang:"lisp"](code/lisp/bubble_sort.lisp)
102104
{% sample lang="nim" %}
103105
[import, lang:"nim"](code/nim/bubble_sort.nim)
106+
{% sample lang="f90" %}
107+
[import, lang:"fortran"](code/fortran/bubble.f90)
104108
{% endmethod %}
105109

106110
<script>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
PROGRAM main
2+
3+
IMPLICIT NONE
4+
REAL(8), DIMENSION(10) :: A
5+
6+
A = (/ 1d0, 3d0, 2d0, 4d0, 5d0, 10d0, 50d0, 7d0, 1.5d0, 0.3d0 /)
7+
8+
WRITE(*,*) 'Input vector'
9+
WRITE(*,'( F6.2 )') A
10+
WRITE(*,*) ' '
11+
12+
CALL bubblesort(A)
13+
14+
WRITE(*,*) 'Output vector'
15+
WRITE(*,'(F6.2)') A
16+
17+
CONTAINS
18+
19+
SUBROUTINE bubblesort(array)
20+
21+
IMPLICIT NONE
22+
INTEGER :: array_length, i, j, n
23+
REAL(8) :: tmp
24+
REAL(8), DIMENSION(:), INTENT(INOUT) :: array
25+
26+
array_length = size(array)
27+
n = array_length
28+
29+
DO i=1, n
30+
DO j=1, n-1
31+
IF ( array(j) > array(j+1) ) THEN
32+
33+
tmp = array(j+1)
34+
array(j+1) = array(j)
35+
array(j) = tmp
36+
37+
END IF
38+
END DO
39+
END DO
40+
END SUBROUTINE bubblesort
41+
42+
END PROGRAM main

0 commit comments

Comments
 (0)