MCPcopy Index your code
hub / github.com/careercup/ctci / search

Method search

java/Chapter 4/Question4_2/Question.java:42–67  ·  view source on GitHub ↗
(Graph g,Node start,Node end)

Source from the content-addressed store, hash-verified

40 }
41
42 public static boolean search(Graph g,Node start,Node end) {
43 LinkedList<Node> q = new LinkedList<Node>();
44 for (Node u : g.getNodes()) {
45 u.state = State.Unvisited;
46 }
47 start.state = State.Visiting;
48 q.add(start);
49 Node u;
50 while(!q.isEmpty()) {
51 u = q.removeFirst();
52 if (u != null) {
53 for (Node v : u.getAdjacent()) {
54 if (v.state == State.Unvisited) {
55 if (v == end) {
56 return true;
57 } else {
58 v.state = State.Visiting;
59 q.add(v);
60 }
61 }
62 }
63 u.state = State.Visited;
64 }
65 }
66 return false;
67 }
68}

Callers 1

mainMethod · 0.95

Calls 4

getAdjacentMethod · 0.95
getNodesMethod · 0.80
addMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected