# sol12 - Cop3530 Solution 12 1 1->1 0 1->2 10 1->4 30...

This preview shows pages 1–3. Sign up to view the full content.

Cop3530 Solution 12 1. 1->1: 0 1->2: 10 1->4: 30 1->4->6: 45 1->4->3: 50 1->4->3->5: 60 2. //a)b) package dataStructures; public class MyLinkedDigraph extends LinkedDigraph { int nodeNumber_; public MyLinkedDigraph(int n) { super(n); nodeNumber_ = n; } boolean visited_[]; int pathk_[]; void FindPathLen(int i,int j,int k) { visited_ = new boolean[nodeNumber_ + 1]; pathk_ = new int[nodeNumber_ + 1]; if(FindPathLenR(i,j,k)) { System.out.println("Path found:"); for (int p = k ; p > 0 ; p--) { System.out.printf(pathk_[p] + "->" );

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
} System.out.printf(pathk_[0] + ""); } else { System.out.println("No path exists."); }; System.out.println(""); System.out.println(""); } boolean FindPathLenR(int i, int j, int k) { visited_[i-1] = true; pathk_[k] = i; if (i == j && k == 0) return true; else if (k > 0) { for (int p = 0; p < aList[i].size; p++) { int u = ((EdgeNode) aList[i].get(p)).vertex; if (!visited_[u-1]) if (FindPathLenR(u, j, k - 1)) return true; } } visited_[i-1] = false; return false; } void FindAllPath(int i,int j)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/15/2010 for the course COP 3530 taught by Professor Davis during the Fall '08 term at University of Florida.

### Page1 / 5

sol12 - Cop3530 Solution 12 1 1->1 0 1->2 10 1->4 30...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online