sol12 - Cop3530 Solution 12 1. 1->1: 0 1->2: 10...

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

View Full Document Right Arrow Icon
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] + "->" );
Background image of page 1

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

View Full DocumentRight Arrow Icon
} 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)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

sol12 - Cop3530 Solution 12 1. 1-&gt;1: 0 1-&gt;2: 10...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online