!********************************************** !* Demonstration program of Merge sorting * !* (about n*log(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: * !* 4 3 1 67 55 8 0 4 -5 37 7 4 2 9 1 -1 * !* * !* Sorted table A: * !* -5 -1 0 1 1 2 3 4 4 4 7 8 9 37 55 67 * !* * !********************************************** Program Merge_Sorting integer i,ialloc,error,n integer, pointer :: a(:) n=16; Allocate(a(0:n-1),STAT=ialloc) a(0)=4; a(1)=3; a(2)=1; a(3)=67 a(4)=55; a(5)=8; a(6)=0; a(7)=4 a(8)=-5; a(9)=37; a(10)=7; a(11)=4 a(12)=2; a(13)=9; a(14)=1; a(15)=-1 print *,' ' print *,' Initial table A:' write(*,10) (a(i),i=0,n-1) call MergeSort(a,n,error) if (error==0) then print *,' ' print *,' Sorted table A:' write(*,10) (a(i),i=0,n-1) end if print *,' ' print *,' ' stop 10 format(16I4) END !Merge Sorting of a() of size m and b() of size n !into c() of size m+n Subroutine Merge(a,b,c,m,n) integer m,n,a(0:m-1),b(0:n-1),c(0:m+n-1) integer i,j,k i=0; j=0; k=0 do while (i