Exemplo n.º 1
0
int main(int argc, char **argv)
{
	Vertex* a = new Vertex("A");
	Vertex* b = new Vertex("B");
	Vertex* c = new Vertex("C");
	Vertex* d = new Vertex("D");
	a->addAdjacent(b);
	a->addAdjacent(c);
	b->addAdjacent(c);
	c->addAdjacent(d);
	Graph* graph = new Graph();
	graph->traverse(a);
	cout << "The distance from D to A is equal to " << d-> getDistance() << endl;
	Vertex* i = d;
	while(i != NULL)
	{
		cout << i -> getName() << endl;
		i = i -> getRoute();
	}

	return 0;
}
Exemplo n.º 2
0
int main()
{
	Graph* g = new Graph();

	Vertex* c = new Vertex("Chicago");
	Vertex* b = new Vertex("Boston");
	Vertex* a = new Vertex("Las Vegas");
	Vertex* d = new Vertex("Detroit");

	a->addAdjacent(b);
	b->addAdjacent(c);
	c->addAdjacent(d);

	g->traverse(a);

	cout << "The trip from " << a->getName() << " to " << d->getName() << " requires " << d-> getDistance() << " flights" << endl;
	Vertex* i = d;
	while(i != NULL){
		cout << i -> getName() << endl;
		i = i -> getRoute();
	}

	return 0;
}