!********************************************** !* Demonstration program of Bubble sorting * !* (about n*n comparisons used). * !* ------------------------------------------ * !* Reference: "A book on C By Al Kelley and * !* Ira Pohl, The Benjamin/Cummings Publishing * !* Company, Inc, 1984" [BIBLI 09]. * !* * !* F90 version by J-P Moreau. * !* (www.jpmoreau.fr) * !* ------------------------------------------ * !* SAMPLE RUN: * !* * !* Initial table A: * !* 7 3 66 3 -5 22 -77 2 36 -12 * !* * !* Sorted table A: * !* -77 -12 -5 2 3 3 7 22 36 66 * !* * !********************************************** Program Bubble_sort parameter(MAX=1024) integer A(1:MAX) n=10 A = 0 A(1)=7; A(2)=3; A(3)=66; A(4)=3; A(5)=-5 A(6)=22; A(7)=-77; A(8)=2; A(9)=36; A(10)=-12 print *,' ' print *,' Initial table A:' write(*,10) (A(i),i=1,n) print *,' ' call Bubble(A,n) print *,' Sorted table A:' write(*,10) (A(i),i=1,n) print *,' ' print *,' ' stop 10 format(10I5) END !return p,q in ascending order Subroutine Order(p,q) integer p,q,temp if (p>q) then temp=p p=q q=temp end if return end !Buuble sorting of integer array A Subroutine Bubble(A, n) integer A(1:n) do i=1, n do j=n, i+1, -1 call Order(A(j-1), A(j)) end do end do return end !end of file bubble.f90