! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

!  Example 7.7. (Fortran 90 version) Linked List implementation of STACK.
   program H07
      use H07M
      implicit none
      integer :: Op
      character (len = STRING_LENGTH) :: Item
!  start program H07
      call Create( )
      do
         write (unit = *, fmt = *) " Please enter Operation: "
         write (unit = *, fmt = *) " 0 to quit; 1 to push; 2 to pop, 3 to peek."
         read (unit = *, fmt = *) Op
         select case (Op)
         case (0)
            write (unit = *, fmt = *) " Operation 0 means quit."
            do
              if (Is_Empty( )) then
                exit
              else
                call Pop( Item )
                write (unit = *, fmt = *) Item, " Left on stack. "
              end if
            end do
            exit
         case (1)
            write (unit = *, fmt = *) " Please enter value (char * 1) to push."
            read (unit = *, fmt = *) Item
            call Push( Item )
            write (unit = *, fmt = *) " Pushed: ", Item
         case (2)
            if (Is_Empty( )) then
               write (unit = *, fmt = *) " Can't pop. Stack is empty."
            else
               call Pop( Item )
               write (unit = *, fmt = *) " Popped: ", Item
            end if
         case (3)
        if (Is_Empty( )) then
               write (unit = *, fmt = *) " Can't peek. Stack is empty."
            else
               call Peek( Item )
               write (unit = *, fmt = *) " Peeked: ", Item
            end if
         case default
            write (unit = *, fmt = *) Op, " is not a valid operation."
         end select
      end do
      stop
   end program H07
