turnerdaniet
Programmer
I AM TRYING TO PRINT OUT A DOUBLY LINKED LIST. I AM ABLE TO GET THE LIST TO PRINT FROM HEAD TO TAIL.. HOWEVER WHEN I PRINT TAIL TO HEAD ONLY THE HEAD WILL PRINT. THIS IS THE LAST PART OF THE CODE. I HAVE INCLUDED THE LINK LIST CODE. ANY SUGGESTIONS?
*INPUT UP TO EOF
NULLIFY(HEAD,TAIL)
DO WHILE(.TRUE.)
READ(1,*,END=999)NAMEIN
READ(1,*,END=999)AGEIN
*INITIALIZE THE POINTERS TO NULL
NULLIFY(CURRENT)
ALLOCATE(CURRENT)
CURRENT%PERSON = NAMEIN
CURRENT%AGE = AGEIN
*IF THERE IS NOT AT LEAST ONE NODE
IF(.NOT.ASSOCIATED(HEAD))THEN
HEAD => CURRENT
TAIL => CURRENT
NULLIFY(HEAD%NEXT,HEAD%PREV)
*IF THE CURRENT IS LAST NODE
ELSE
*PLACE AT END OF LIST
TAIL%NEXT =>CURRENT
CURRENT%PREV=>TAIL
NULLIFY(CURRENT%NEXT)
*CHANGE TAIL POINTER TO NEW END
TAIL => CURRENT
NULLIFY(CURRENT%NEXT)
NULLIFY(CURRENT%PREV)
END IF
END DO
999 CONTINUE
*PRINT FROM HEAD TO TAIL
*POINT TO THE BEGINNING
NULLIFY(TEMP)
TEMP => HEAD
*PRINT EACH NODE
PRINT *,'-----PRINTING fROM HEAD TO TAIL-----'
DO WHILE(ASSOCIATED(TEMP))
PRINT 5,TEMP%PERSON
PRINT 10,TEMP%AGE
TEMP => TEMP%NEXT
END DO
*PRINT FROM TAIL TO HEAD
*POINT TO THE BEGINNING
*PRINT EACH NODE
CURRENT => TAIL
PRINT *,'-----PRINTING fROM TAIL TO HEAD------'
DO WHILE(ASSOCIATED(TEMP))
PRINT 5,CURRENT%PERSON
PRINT 10,CURRENT%AGE
CURRENT => CURRENT%PREV
END DO
*INPUT UP TO EOF
NULLIFY(HEAD,TAIL)
DO WHILE(.TRUE.)
READ(1,*,END=999)NAMEIN
READ(1,*,END=999)AGEIN
*INITIALIZE THE POINTERS TO NULL
NULLIFY(CURRENT)
ALLOCATE(CURRENT)
CURRENT%PERSON = NAMEIN
CURRENT%AGE = AGEIN
*IF THERE IS NOT AT LEAST ONE NODE
IF(.NOT.ASSOCIATED(HEAD))THEN
HEAD => CURRENT
TAIL => CURRENT
NULLIFY(HEAD%NEXT,HEAD%PREV)
*IF THE CURRENT IS LAST NODE
ELSE
*PLACE AT END OF LIST
TAIL%NEXT =>CURRENT
CURRENT%PREV=>TAIL
NULLIFY(CURRENT%NEXT)
*CHANGE TAIL POINTER TO NEW END
TAIL => CURRENT
NULLIFY(CURRENT%NEXT)
NULLIFY(CURRENT%PREV)
END IF
END DO
999 CONTINUE
*PRINT FROM HEAD TO TAIL
*POINT TO THE BEGINNING
NULLIFY(TEMP)
TEMP => HEAD
*PRINT EACH NODE
PRINT *,'-----PRINTING fROM HEAD TO TAIL-----'
DO WHILE(ASSOCIATED(TEMP))
PRINT 5,TEMP%PERSON
PRINT 10,TEMP%AGE
TEMP => TEMP%NEXT
END DO
*PRINT FROM TAIL TO HEAD
*POINT TO THE BEGINNING
*PRINT EACH NODE
CURRENT => TAIL
PRINT *,'-----PRINTING fROM TAIL TO HEAD------'
DO WHILE(ASSOCIATED(TEMP))
PRINT 5,CURRENT%PERSON
PRINT 10,CURRENT%AGE
CURRENT => CURRENT%PREV
END DO