用链表。
[Fortran] 纯文本查看 复制代码 Program www_fcode_cn
Implicit None
Integer :: iCount , i
Real :: rRead
Type :: stPLink
Real :: rValue
Type(stPLink) , Pointer :: pNext
End Type stPLink
Type( stPLink ) , Target :: stLocal
Type( stPLink ) , Pointer :: pLocal
pLocal => stLocal
iCount = 0
rRead = 1.0
write(*,*) '请输入一些数,输入0结束:'
Do
Read(*,*) rRead
If ( rRead < 0.0001 ) then
Exit
End If
pLocal%rValue = rRead
Allocate( pLocal%pNext )
pLocal => pLocal%pNext
iCount = iCount + 1
End Do
pLocal => stLocal
Do i = 1 , iCount
Write(*,*) pLocal%rValue
pLocal => pLocal%pNext
End Do
End Program www_fcode_cn |