Exemple #1
0
void DigraphL::print(void) {
	// Wagi krawedzi od 'v' do kazdego z V wierzcholkow (moga byc nieskonczone)
	int matrix[V];	
	HalfEdge* edge;
			
 	for (int v = 0; v < V; v++) {
		edges[v]->rewind();
		// Inicjujemy tablice nieskonczonymi wagami
 		for (int w = 0; w < V; w++)
			matrix[w] = INF;	
		
		// Uaktualniamy wagi odpowadajace istniejacym krawedziom
		while (edges[v]->hasMoreElements()) {
			edge = edges[v]->getNext();
			matrix[edge->getEndingVertexIndex()] = edge->getWeight();
		}
		
		// Wypisujemy wagi na ekran
  		for (int w = 0; w < V; w++) {
			cout << "\t";
 			if (matrix[w] != INF)
				cout << matrix[w];
			else
				cout << "-";
		}
		cout << endl;
	}
	cout << endl;
}
Exemple #2
0
long DigraphL::getWeight(int v, int w) {
	if (v >= 0 && w >=0 && v < V && w < V) {
		HalfEdge* edge;		
		edges[v]->rewind();
		while (edges[v]->hasMoreElements()) {
			edge = edges[v]->getNext();
			if (edge->getEndingVertexIndex() == w)
				return edge->getWeight();
		}
		return INF;
	}
	else
		return INF;	
}