Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Iterable<Vertice<V>> buscarCamino(Vertice<V> origen,
- Vertice<V> destino) {
- TDALista<Vertice<V>> l = new TDALista<Vertice<V>>();
- for (Vertice<V> v : vertices()) {
- try {
- visitados.put(v, false);
- } catch (InvalidKeyException e) {
- }
- }
- buscarCamino(origen, destino, l);
- return l;
- }
- // COPIAR (Es como un DFS)
- private boolean buscarCamino(Vertice<V> origen, Vertice<V> destino,
- TDALista<Vertice<V>> l) {
- try {
- l.addLast(origen);
- visitados.put(origen, true);
- if (origen == destino) {
- return true;
- } else {
- for (Arco<A> a : incidentEdges(origen)) {
- Vertice<V> vecino = opposite(origen, a);
- if (!visitados.get(vecino)) {
- boolean encontre = buscarCamino(vecino, destino, l);
- if (encontre)
- return true;
- }
- }
- // Si ando por aca ya a partir del origen no llego a destino
- // Borro el ultimo que agrege a la lista!
- l.remove(l.last());
- return false;
- }
- } catch (InvalidKeyException e) {
- } catch (InvalidPositionException e) {
- } catch (EmptyListException e) {
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement