I am creating a doubly linked list in fortran. Pretty much everything is working correctly. Although, I am having one issue... I build the list properly, but when printed to the screen, I get jumble for the first and last lines. Here is my code
DO WHILE (.NOT. quit .AND. inStat .EQ. 0)
ALLOCATE(cur) !create a new node
NULLIFY(cur%prev,cur%next) !nullify the pointers
IF (.NOT. ASSOCIATED(head)) THEN
!start a new doubly linked list
ALLOCATE(head) !create a head
NULLIFY(head%prev,head%next) !nullify head's pointers
ALLOCATE(tail) !create a tail
NULLIFY(tail%prev,tail%next) !nullify tail's pointers
head => cur !point head to cur
READ(1,*,IOSTAT=inStat)cur%name !store name in cur
READ(1,*,IOSTAT=inStat)cur%cnt !store count in cur
ELSE
cur%prev => tail !point cur's prev to the previous tail
tail%next => cur !point tail's next to cur
READ(1,*,IOSTAT=inStat)cur%name !store name in cur
READ(1,*,IOSTAT=inStat)cur%cnt !store cnt in cur
END IF
tail => cur !point tail to cur
END DO
cur => head !point cur to head
DO WHILE (ASSOCIATED(cur)) !while there is more
PRINT *,cur%name, ' ', cur%cnt
cur => cur%next
END DO
The input file contains the following:
nick
7
jim
5
mike
16
rob
15
steven
16
johnathan
-5
What is printed:
J↓K l■( ─ ( e┬æuƒ 704
nick 7
jim 5
mike 16
rob 15
steven 16
johnathan -5
P_K └ K 0