   SUBROUTINE PrintList(head)
    USE ListModule
    IMPLICIT NONE

    type( ListElem ), pointer :: head
    type( ListElem ), pointer :: ptr

    ptr => head

    print *, "The list is: "
    DO WHILE ( associated(ptr) )
      print *, ptr%f
      ptr => ptr%next
    END DO
    print *
   END SUBROUTINE

! =======================================


   PROGRAM Pj7
    USE ListModule

    INTERFACE
      SUBROUTINE PrintList(head)
       USE ListModule
       type( ListElem ), pointer :: head
      END SUBROUTINE
    END INTERFACE

    INCLUDE 'pj7interface.h'

    type( ListElem ), pointer :: head
    type( ListElem ), pointer :: newElem
    integer, parameter :: N = 4

   nullify( head )                 ! Initialize list to point to no target.

   PRINT *, "Testing insert into empty list:"
   ALLOCATE( newElem )
   newElem%f = 1500
   CALL InsertOrdered(head, newElem)
   CALL PrintList(head)

   PRINT *, "Testing insert into end of list:"
   ALLOCATE( newElem )
   newElem%f = 2500
   CALL InsertOrdered(head, newElem)
   CALL PrintList(head)

   PRINT *, "Testing insert at head of list:"
   ALLOCATE( newElem )
   newElem%f = 1000
   CALL InsertOrdered(head, newElem)
   CALL PrintList(head)

   PRINT *, "Testing insert at middle of list:"
   ALLOCATE( newElem )
   newElem%f = 2000
   CALL InsertOrdered(head, newElem)
   CALL PrintList(head)

   END PROGRAM

