예제 #1
0
LList<T> neighbours(graph<T> g, T e) {
  if (!g.top(e)) {
    return LList<T>();
  }

  elem<T> * glist = g.point(e);
  LList<T> neighbours;
  while (glist->link != NULL) {
    neighbours.ToEnd(glist->link->inf);
    glist = glist->link;
  }
  return neighbours;
}
예제 #2
0
void fillGraph(graph<int>& g, vector<Edge>& e){	// trqbva da se polzva vector<City>!!!
	for (int i = 0; i < e.size(); i++){

		if (!g.top(e[i].idA)) g.addTop(e[i].idA);
		if (!g.top(e[i].idB)) g.addTop(e[i].idB);

		g.addRib(e[i].idA, e[i].idB);
		g.addRib(e[i].idB, e[i].idA);


	}

}
예제 #3
0
void notFurtherThan(int& dist, int& start, graph<int>& g, LList<int>& visited, LList<int>& cities)
{
	if (contains(visited, cities)) return; // ??? should be contains(visited, start)
	if (dist < 0) return;
	if (!g.top(start)) return;
	visited.ToEnd(start);
	cities.ToEnd(start);
	elem<int>* q = g.point(start);
	q = q->link;

	while (q)
	{
		int distance = dist - 1;
		notFurtherThan(distance, q->inf, g, visited, cities);
		q = q->link;
	}
}