Algoritma Dijkstra: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
k Bot: Mengganti Dijksta_Anim.gif dengan Dijkstra_Animation.gif |
→Pseudocode: Update code |
||
Baris 17:
== Pseudocode ==
1 '''function''' Dijkstra(
2 '''for each''' vertex ''v'' in
3
4 previous[v] := undefined▼
5
6 '''end for''' ''// from source''
7
▲ 7 Q := V[G] ''// Set of all vertices''
8 dist[''
9 ''Q'' := the set of all nodes in ''Graph'' ; ''// All nodes in the graph are''
10 ''// unoptimized - thus are in Q''
10 S := S union {u}▼
11 '''while''' ''Q'' '''is not''' empty: ''// The main loop''
12 ''u'' := vertex
13 remove
14 '''if'''
15 '''break''' ; ''// all remaining vertices are''
16 '''end if''' ''// inaccessible from source''
17
18 '''for each''' neighbor ''v'' of ''u'': ''// where v has not yet been''
19 ''// removed from Q.''
20 ''alt'' := dist[''u''] + dist_between(''u'', ''v'') ;
21 '''if''' ''alt'' < dist[''v'']: ''// Relax (u,v,a)''
22 dist[''v''] := ''alt'' ;
24 decrease-key ''v'' in ''Q''; ''// Reorder v in the Queue''
26 '''end for'''
27 '''end while'''
28 '''return''' dist;
== Rujukan ==
|