diff --git a/Uebung/SoSe24/Queue.f95 b/Uebung/SoSe24/Queue.f95 index 69f685b6c3c21992eec0810d38f46440e88fefc6..67265d834259f4f8630a798218dfe4796d6c3efd 100644 --- a/Uebung/SoSe24/Queue.f95 +++ b/Uebung/SoSe24/Queue.f95 @@ -44,16 +44,62 @@ program QueueProgram contains subroutine enqueue(myQueue, name) + type(Queue), intent(inout) :: myQueue + type(QueueElement), pointer :: newQueueElement + character(20), intent(in) :: name + allocate(newQueueElement) + newQueueElement%name = name + + if(.not.associated(myQueue%head)) then + myQueue%head => newQueueElement + else + myQueue%tail%next => newQueueElement + end if + + myQueue%tail => newQueueElement end subroutine enqueue subroutine dequeue(myQueue, name) + type(Queue), intent(inout) :: myQueue + type(QueueElement), pointer :: deleteQueueElement + character(20), intent(out), optional :: name + + if(associated(myQueue%head)) then + + if(associated(myQueue%head, myQueue%tail)) then + myQueue%tail => null() + end if + + deleteQueueElement => myQueue%head + myQueue%head => deleteQueueElement%next + if(present(name))then + name = deleteQueueElement%name + end if + + deallocate(deleteQueueElement) + end if end subroutine dequeue subroutine traverse(myQueue, task) + type(Queue), intent(inout) :: myQueue + type(QueueElement), pointer :: current + + interface + subroutine task(name) + character(20), intent(inout):: name + end subroutine task + end interface + current => myQueue%head + + do while(associated(current)) + call task(current%name) + current => current%next + end do + end subroutine traverse