0
隣接リスト方式を使用してグラフを作成しています。各ノードは、それに接続された他のノードを指すノードとして表されます。以下は、私のコードです隣接リストを使用してグラフを構築中のFortranでのセグメント化エラー
program main
use graphs
implicit none
type(node),pointer :: start
type(node), dimension(:), pointer :: grp
integer :: n, ios=0, a,b, i
open(1, file='test6.txt', status='OLD', action='READ')
read(1,*,iostat=ios) n
allocate(start)
allocate(grp(n))
do, i=1,n
grp(i)%val=i
enddo
do while(ios==0)
read(1,*, iostat=ios)a,b
if(ios.NE.0)then
exit
endif
start => grp(a)
call add(start, b)
start => grp(b)
call add(start, a)
end do
end program main
私は次のエラー
Program received signal SIGSEGV: Segmentation fault - invalid memory
reference
Backtrace for this error:
#0 0x7f786df6bef7 in ???
#1 0x7f786df6b12d in ???
#2 0x7f786dbbc4af in ???
#3 0x401db0 in __graphs_MOD_add
at /home/nav/MS project/new/grph.f90:18
#4 0x400f48 in ???
#5 0x400f85 in ???
#6 0x7f786dba782f in ???
#7 0x400a18 in ???
#8 0xffffffffffffffff in ???
Segmentation fault (core dumped)
に取得しています
43
1 2
1 10
2 3
2 11
3 4
4 5
5 6
6 7
7 8
8 9
3 12
4 13
5 14
6 15
7 16
8 17
9 18
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
10 19
11 19
12 20
を次のようにtest6.txt
がある
module graphs
type node
integer :: val
type(node), pointer :: next
end type node
contains
subroutine add(strt, nxn)
implicit none
type(node), pointer :: strt, new_node, lst
integer :: nxn
allocate(new_node)
allocate(lst)
lst => strt
new_node%val = nxn
new_node%next => NULL()
do while(associated(lst%next))
lst => lst%next
enddo
lst%next => new_node
end subroutine add
end module graphs
ファイルを次のようにモジュールのグラフでありますザ・アブーヴeプログラムは小さなグラフではスムーズに動作しますが、大きなグラフでは動作しません。私は何が間違っているのかを知ることができないのですか?私はgfortranコンパイラを使用しています。
これは 'allocate(l(n))'には何がありますか? 'l'はどこにも宣言されていないようです。 – agentp
'project/new/grph.f90:18'の行を見せてもらえますか? – Brick
@agentp以前この配列を使用していました。私はそれを削除することを忘れない。 – Neobux