Witam!

Mam problem z algorytmem Dijkstry. Proszę o pomoc. Wyrzuca mi na konsolę segmentation fault.

``````void Dijkstra(Graph & h, int poczatkowy, int koncowy, vector<int> &trasa)
{
int numberOfVertices = h.NumberOfVertices();

bool *known = new bool[numberOfVertices];
int *distance = new int[numberOfVertices];
int *predecessor = new int[numberOfVertices];
trasa.resize(0);

priority_queue<int> kolejka;

for(int i = 0; i < numberOfVertices; i++)
{
known[i] = false;
distance[i] = 999999;
predecessor[i] = -1;
}

distance[poczatkowy] = 0;
kolejka.push(poczatkowy);

while( !kolejka.empty() )
{
int v = kolejka.top();
kolejka.pop();

if( known[v] != true)
{
known[v] = true;
Iterator<Edge> &iter = h.EmanatingEdges(v);

while( !iter.IsDone() )
{
Edge &e = *iter;
Vertex &w = e.mate(v);
int d = distance[v] + e.weight;
int wnumber = w.Number();
if( distance[wnumber] > d )
{
distance[wnumber] = d;
predecessor[wnumber] = v;
kolejka.push(wnumber);
}
++iter;
}
}
}
int i = 1;
trasa[0] = koncowy;
do
{
trasa[i] = predecessor[trasa[i-1]];
++i;
}while (predecessor[i] != poczatkowy);
}

void Shortest_path (GraphAsList g, int poczatek, int koniec)
{
vector<int> trasa;
Dijkstra(g, poczatek, koniec, trasa);
int i = trasa.size();
while ( i != 0)
{
cout << g.SelectVertex(trasa[i]).label << " - " << g.SelectVertex(trasa[--i]).label << " " << g.SelectEdge(trasa[i+1], trasa[i]).weight << endl;
}
}
``````