Advertisement
Guest User

Untitled

a guest
Jun 10th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module sort
  2.  
  3. use Environment
  4. use List_IO  
  5.  
  6.    implicit none
  7.  
  8.  
  9.  
  10. contains
  11.     pure recursive subroutine Sort_List(Custom_List, N)
  12.            type(List), pointer, intent(inout) :: Custom_List
  13.            integer, intent(in)  :: N
  14.  
  15.  
  16.            call Drop_down(Custom_List, 1, N-1)
  17.  
  18.            if( N >= 3) call Sort_List(Custom_List,N-1)
  19.  
  20.    end subroutine Sort_List
  21.  
  22.    pure recursive subroutine Drop_down(Custom_List,j,N)
  23.           type(List),pointer :: Custom_List
  24.           integer, intent(in) :: j,N
  25.  
  26.  
  27.           if (Swap(Custom_List)) call Swap_from_cur(Custom_List)
  28.           if (j < N) call Drop_down(Custom_List%next,j+1,N)
  29.    end subroutine Drop_down
  30.  
  31.    pure logical function Swap(current_elem)
  32.           type(List), intent(in) :: current_elem
  33.  
  34.           Swap = .false.
  35.           if (current_elem%Surname >  current_elem%next%Surname) then
  36.             Swap = .true.
  37.           else if (current_elem%Surname == current_elem%next%Surname &
  38.                    .and. current_elem%Initials >  current_elem%next%Initials) then
  39.             Swap = .true.
  40.          end if        
  41.    end function Swap
  42.  
  43.    pure subroutine Swap_from_cur(current_elem)
  44.            type(List), pointer :: current_elem
  45.            
  46.            type(List), pointer :: tmp_elem
  47.            
  48.            tmp_elem => current_elem%next
  49.            current_elem%next => current_elem%next%next
  50.            tmp_elem%next => current_elem
  51.            current_elem => tmp_elem  
  52.    end subroutine Swap_from_cur
  53.  end module sort
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement