Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module sort
- use Environment
- use List_IO
- implicit none
- contains
- pure recursive subroutine Sort_List(Custom_List, N)
- type(List), pointer, intent(inout) :: Custom_List
- integer, intent(in) :: N
- call Drop_down(Custom_List, 1, N-1)
- if( N >= 3) call Sort_List(Custom_List,N-1)
- end subroutine Sort_List
- pure recursive subroutine Drop_down(Custom_List,j,N)
- type(List),pointer :: Custom_List
- integer, intent(in) :: j,N
- if (Swap(Custom_List)) call Swap_from_cur(Custom_List)
- if (j < N) call Drop_down(Custom_List%next,j+1,N)
- end subroutine Drop_down
- pure logical function Swap(current_elem)
- type(List), intent(in) :: current_elem
- Swap = .false.
- if (current_elem%Surname > current_elem%next%Surname) then
- Swap = .true.
- else if (current_elem%Surname == current_elem%next%Surname &
- .and. current_elem%Initials > current_elem%next%Initials) then
- Swap = .true.
- end if
- end function Swap
- pure subroutine Swap_from_cur(current_elem)
- type(List), pointer :: current_elem
- type(List), pointer :: tmp_elem
- tmp_elem => current_elem%next
- current_elem%next => current_elem%next%next
- tmp_elem%next => current_elem
- current_elem => tmp_elem
- end subroutine Swap_from_cur
- end module sort
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement