前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【旧代码】fortran中的指针实现链表的代码

【旧代码】fortran中的指针实现链表的代码

作者头像
byronhe
发布2021-06-25 10:45:24
7240
发布2021-06-25 10:45:24
举报
文章被收录于专栏:Tech Explorer

我不喜欢fortran,

奇怪的词法规则(竟然不用空格分开token),

io操作竟然是语言的一部分(这种非本质的东西像C那样用库来扩展多好)

。。。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

program link implicit none type node character(20) name integer id integer score type(node),pointer ::next end type integer,parameter::num=3 type(node),pointer ::students call init_all(students,num) call show_all(students) print*,"now,we add a student" call add_node(students) call show_all(students) print*,"now,we delete the student" call del_node(students) call show_all(students) contains subroutine add_node(pos) type(node),pointer ::pos,tmp allocate(tmp) tmp%name="abc" tmp%id=1 tmp%score=100 print*,"please input name,id,end score of one students" read*,tmp%name,tmp%id,tmp%score if(associated(pos%next)) then tmp%next=>pos%next pos%next=>tmp else nullify(tmp%next) pos%next=>tmp end if end subroutine subroutine del_node(pos) type(node),pointer ::pos,next next=>pos%next if(associated(next%next)) then pos%next=>next%next deallocate(next) else nullify(pos%next) deallocate(next) end if end subroutine subroutine show_all(pos) type(node),pointer ::pos,tmp integer ::cnt cnt=1 print*,"all students are:" tmp=>pos do while(associated(tmp)) print*,cnt,"th ",tmp%name,tmp%id,tmp%score tmp=>tmp%next cnt=cnt+1 end do end subroutine subroutine init_all(pos,num) type(node),pointer ::pos,tmp,walk integer num integer i allocate(tmp) nullify(tmp%next) call add_node(tmp) pos=>tmp%next deallocate(tmp) walk=>pos do i=1,num-1 call add_node(walk) walk=>walk%next end do end subroutine end program link

我很少讨厌某种技术,坦诚的说,关于fortran,是有其他因素参合进来了。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2011-11-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档